Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set selected item in combobox - vb.net

I am using this code to add a value to a combobox different then the one displayed: how to add value to combobox item

Lets suppose i have 3 values in my Combobox:

 item 1
 item 2
 item 3

If i chose item 2 from the dropdown the code in the link works. But if i TYPE item 2 manually it doesnt work because i think that typing it only sets the combobox1.text value and not the combobox1.selecteditem. I can type a value present in the dropdown, or one not present. If i type one that is present, then the selectedItem property should also be set to the proper value. can this be done?

Thanks

like image 540
sharkyenergy Avatar asked Nov 05 '13 10:11

sharkyenergy


1 Answers

solved this way:

Private Sub ComboBox1_Keyup(sender As Object, 
  e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp

      ComboBox1.SelectedIndex = ComboBox1.FindStringExact(ComboBox1.Text)

End Sub
like image 65
sharkyenergy Avatar answered Sep 27 '22 23:09

sharkyenergy