SBendBuckeye
Programmer
Hello all,
I am using the following code to try and match an item in a combobox. The ObjectCollection count is zero when it should be 3 as the combobox Items.Count = 3.
Thanks in advance for any ideas and/or suggestions!
I am using the following code to try and match an item in a combobox. The ObjectCollection count is zero when it should be 3 as the combobox Items.Count = 3.
Code:
' Fill combobox with integers.
Me.ComboBox1.Items.Add(1)
Me.ComboBox1.Items.Add(2)
Me.ComboBox1.Items.Add(3)
Me.ComboBox1.SelectedIndex = 1
Code:
Public Sub SetSelectedItem(ByVal selectedItem As Object)
Try
If Not Me.ComboBox1.FindForm.ContainsFocus Then Return
' Get combobox items collection.
Dim collection As ObjectCollection = _
New ObjectCollection(Me.ComboBox1)
' Get associated index for requested item.
Me.ComboBox1.SelectedIndex = _
collection.IndexOf(selectedItem)
Catch ex As Exception
Throw
End Try
End Sub 'SetSelectedItem