[RESOLVED] [2005] combobox databinding
im trying to bind dataset at runtime to combobox with the valuemember and displaymember column assign. im playing this code
vb Code:
ComboBox1.DataSource = ds.Tables(0)
ComboBox1.ValueMember = "pk_clientID"
ComboBox1.DisplayMember = "clientname"
to make the name appear in the combobox item list and on the other hand the ID will be use for details referencing.
tnx
Re: [2005] combobox databinding
Re: [2005] combobox databinding
oops why did i post that unfinish. anyway here the remaining part:
vb Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
MessageBox.Show(ComboBox1.ValueMember)
End Sub
and this return the string "pk_clientID" regardless of what ive selected in the combobox item its return the same value.
Re: [2005] combobox databinding
:wave:
Yes, the valuemember only gets/sets the field in the datasource to use for the value property. To get the value that is selected use combobox1.selectedvalue.
Re: [2005] combobox databinding
i think you are looking for
Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
MessageBox.Show(ComboBox1.SelectedValue)
End Sub
Re: [2005] combobox databinding