|
-
Jan 26th, 2006, 07:37 AM
#1
Thread Starter
Hyperactive Member
After update on Combo box [Resolved]
Hi I have a combo box, which is bound to some data like so.
VB Code:
Private Sub getmaindropdata()
Try
Dim dacontcom As New SqlDataAdapter
ds.Tables("ContactsCom").Clear()
Dim spgetconcom As New SqlCommand("spgetconcom", sqlcon, Nothing)
spgetconcom.CommandType = CommandType.StoredProcedure
dacontcom.SelectCommand = spgetconcom
sqlcon.Open()
dacontcom.Fill(ds, "ContactsCom")
sqlcon.Close()
Me.cbocompany.DataSource = ds
Me.cbocompany.DisplayMember = "ContactsCom.CompanyName"
Me.cbocompany.ValueMember = "ContactsCom.ContactID"
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Now I can't quite get my head out of a VBA mindset, but basically how do I do the below in .net
VB Code:
Private Sub cbocompany_AfterUpdate()
popfields(me.cbocompany) ' me.cbocompany would give me the contactid
End Sub
As always any help would be very much appricated.
Last edited by Oliver1; Jan 26th, 2006 at 11:34 AM.
Reason: Resolved
-
Jan 26th, 2006, 07:51 AM
#2
Re: After update on Combo box
What update is this event supposed to be raised after and what is popfields supposed to be doing? If you mean after the DataSource is assigned then there is a DataSourceChanged event. If you mean after the user selects an item then there is a SelectedIndexChanged event.
-
Jan 26th, 2006, 07:57 AM
#3
Thread Starter
Hyperactive Member
Re: After update on Combo box
Sorry popfield is just a function that puts data in other fields depending on the item the user has selected from the combo box.
I got this far
VB Code:
Private Sub cbocompany_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbocompany.SelectedIndexChanged
popfields(Me.BindingContext(ds, "ContactsCom.ContactID").Current())
End Sub
But I think I should reference the value in the combo box rather than the datatable (even though i think the should be the same). My problem is the above works but it is always one record behind, eg the contactid is not the record that has just been selected, it's the previous record.
-
Jan 26th, 2006, 08:00 AM
#4
Re: After update on Combo box
you can use cbocompany.SelectedItem to get whatever item the user has selected. Although i havnt ever used binding so i dont know if that doesnt work with it, but in normal context hat is how to do it
-
Jan 26th, 2006, 11:33 AM
#5
Thread Starter
Hyperactive Member
Re: After update on Combo box
Thanks
popfields(cbocompany.SelectedValue)
works and overcomes the other problem I had.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|