display member and value member in combo box
-
Dienstag, 6. März 2012 03:24
hi.
i have two combo boxes. the first one is where i store the IDNumbers and the other one is where i store the Name.
the code when I choose from cboNames then the cboID automatically changes is working well. my problem is when i double click my listview the cboNames has no values but the cboID has.
my code----
Private Sub cboName_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboName.SelectedValueChanged selectedText = cboName.SelectedIndex cboID.SelectedIndex = selectedText End Sub ................ Dim strSQL As String = "SELECT * FROM classification" Dim da As New MySqlDataAdapter(strSQL, conBooks) Dim ds As New DataSet da.Fill(ds, "classification") With cboName .DisplayMember = "ClassDesc" .ValueMember = "ClassID" .DataSource = ds.Tables("classification") End Withi really2x need HELP.. T.T
Alle Antworten
-
Dienstag, 6. März 2012 09:28
Why do you hav 2 comboBoxes? Are both of them connected with the same object (id and name)? If, no need of two, one will do just fine.
What about your table names? IS "ClassDesc" you full name of the column?
Here is an example how to bind and retreive data from bind comboBox:
'lets assume your combobox has name comboBox1!!! 'and lets bind id and a name to it (to one combobox)!! Dim strSQL As String = "SELECT * FROM classification" Dim da As New MySqlDataAdapter(strSQL, conBooks) Dim ds As New DataSet() da.Fill(ds, "classification") comboBox1.DisplayMember = "Name_Column" 'change this comboBox1.ValueMember = "ID_Column" 'change this comboBox1.DataSource = New BindingSource(ds.Tables("classification"), Nothing) 'retreiving in selectedIndexChanged event: Dim view As DataRowView = TryCast(comboBox1.SelectedItem, DataRowView) 'if ID column is an integer: Dim id As Integer = Integer.Parse(view("ID_Column")) Dim name As String = view("Name_Column").ToString() 'now you can use id (value) and name (item) from comboBox to show or set some other...!Hope it helps,
bye
Mitja
- Als Antwort vorgeschlagen Amit Govil Dienstag, 6. März 2012 17:15
- Als Antwort markiert Bob Wu-MTMicrosoft Contingent Staff, Moderator Montag, 12. März 2012 06:38

