Hi!
Please help.
I have a combobox with datasource set to a two column DataTable with id and title. Displaymember is title, valuemember is id.
I can't find a way, how I could find the combobox.index of the item with a selected id.
I need to set the combobox to a specific value based on other selections. I try to get a function like this:
Please help.
I have a combobox with datasource set to a two column DataTable with id and title. Displaymember is title, valuemember is id.
Code:
Dim myOleDBCommand As New OleDbCommand()
myOleDBCommand.Connection = newConn
myOleDBCommand.CommandText = "select id, title from company where is_buyer <> 0 order by title"
Dim myTable As New DataTable
Dim myOtherFillAdapter As New OleDbDataAdapter(myOleDBCommand)
myOtherFillAdapter.Fill(myTable)
If myTable.Rows.Count > 0 Then
With cmbBuyer
.DataSource = myTable
.DisplayMember = "title"
.ValueMember = "id"
End With
End If
I need to set the combobox to a specific value based on other selections. I try to get a function like this:
Code:
Function SelectComboID(ByRef c As System.Windows.Forms.ComboBox, ByRef ID As Object) As Object
Dim i As Integer
If c.Items.Count = 0 Then Exit Function
For i = 0 To c.Items.Count - 1
If c.Items(i).Value = ID Then
c.SelectedIndex = i
Exit Function
End If
Next i
End Function