ComboBox Bug?

  • Thread starter Thread starter Sebastian
  • Start date Start date
S

Sebastian

Hello,

i added a datasource to the ComboBox and set the display member. Now there
are 12 entries in it. All works fine. But if i want the index of the item
thats entry is for example "Test" and i use the function contains and
indexof , i ll allways get back -1. what should i do if i want check if a
string is in the combobox or not?

Thanks in advance
 
hello, Sebastian,
using ComboBox.Items.IndexOf should work. Have you checked whether the the
string you give exactly matches the one in the ComboBox? Returnning -1
means it can't find the string. For example, the string in your data entry
might have some extra spece, or the casing doesn't match exactly. The
comparison itself is case sensitive.
Thanks
Xin
 
I'd suggest that Xin Yan try this himself because it's definetely a bug.
I've found the combobox to a datatable (settings the valuemember and
display member) and it simply doesn't work.
 
Yes, i think its a bug. It wont work. MS should take this in list to be
fixed.
Here my workaround:

Me.myCombo.Text = "Test"
If Not (Me.myCombo.Text.Equals("Test")) Then
Me.myCombo.SelectedIndex = -1
End If

First i set the Text of the combo for the searching entry. Then i check if
the Text equals the entry. if true then the entry is in the itemcollection
else it isn't so set the index to -1 and no item is shown.

i hope it will help anybody.

Sebastian
 
Back
Top