11

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

4

1 回答 1

31

以这种方式解决:

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

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

End Sub
于 2013-11-05T12:06:55.687 回答