conrad2010
asked on
Select item in combobox
how can I select an item in a combobox filled with items?
I am using KeyValuePairs (see attached code).
Say I have 100 items in the combobox and if a project exists, the form loads with that project selected...
I am using KeyValuePairs (see attached code).
Say I have 100 items in the combobox and if a project exists, the form loads with that project selected...
'// fill the combobox with KeyValuePairs
For i As Integer = 0 To datatable.Rows.Count - 1
combobox1.Items.Add(New clsKeyValuePair(datatable.Rows(i).Item("PROJECT_ID"), datatable.Rows(i).Item("PROJECT_NAME")))
Next
'// KeyValuePairs class
Public Class clsKeyValuePair
Public Key As Object
Public Value As String
Public Sub New(ByVal NewValue As Object, ByVal NewDescription As String)
Key = NewValue
Value = NewDescription
End Sub
Public Overloads Overrides Function ToString() As String
Return Value
End Function
End Class
ASKER
it's the other way around...
I load kv from the database and show it as selected in the combobox...
I load kv from the database and show it as selected in the combobox...
If you know the index, you can use the SelectedIndex property
ComboBox1.SelectedIndex = 3
ComboBox1.SelectedIndex = 3
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
kv= combobox1.selecteditem