set selected item in combobox - vb.net

拈花ヽ惹草 提交于 2020-01-01 04:43:08

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/19786889/set-selected-item-in-combobox-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!