在combobox - vb.net中设置所选项目 [英] set selected item in combobox - vb.net

查看:479
本文介绍了在combobox - vb.net中设置所选项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码为一个组合框添加一个不同于显示的值的值:如何为组合框项目添加值



假设我在Combobox中有3个值:

  item 1 
item 2
item 3


b $ b

如果我从下拉菜单中选择项目2 ,则链接中的代码将起作用。但是如果我TYPE 项目2 手动它不工作,因为我认为键入它只设置 combobox1.text 值和不是 combobox1.selecteditem 。我可以在下拉列表中输入一个值,或者不存在。如果我键入一个存在,那么selectedItem属性也应该设置为正确的值。

解决方案

这样解决:



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


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

解决方案

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

这篇关于在combobox - vb.net中设置所选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆