Link to home
Start Free TrialLog in
Avatar of conrad2010
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...
'// 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

Open in new window

Avatar of UnifiedIS
UnifiedIS

dim kv as clsKeyValuePair
kv= combobox1.selecteditem


Avatar of conrad2010

ASKER

it's the other way around...

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
ASKER CERTIFIED SOLUTION
Avatar of lppperes
lppperes
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial