Set selected item in combobox - vb.net

I use this code to add a value to the combo box other than the one displayed: how to add a value to the combobox element

Suppose I have 3 values ​​in my Combobox:

item 1 item 2 item 3 

If I selected item 2 from the drop-down list, the code in the link works. But if I TYPE item 2 manually, this does not work, because I think entering it only sets the value of combobox1.text , not combobox1.selecteditem . I can enter the value present in the drop-down list, or one of them is missing. If I type one that is present, then the selectedItem property must also be set to the correct value. It can be done?

thanks

+7
text combobox selecteditem
source share
2 answers

solved this method:

 Private Sub ComboBox1_Keyup(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp ComboBox1.SelectedIndex = ComboBox1.FindStringExact(ComboBox1.Text) End Sub 
+21
source share

Many thanks. It worked. StateCmb.SelectedIndex = StateCmb.FindStringExact (rdr ("StateName"))

0
source share

All Articles