我想创建一个ComboBox,根据输入自动删除包含字母的单词。我的下拉式是下拉式,因此组合框有一个输入字段。
例如,我会输入字母A或我希望ComboBox自动下拉包含字母A或a的单词。 ComboBox的内容由我自己手动设置。
这可能吗?提前谢谢。
答案 0 :(得分:2)
你必须设置这些
AutoCompleteMode: SuggestAppend
AutoCompleteSource: ListItems
DropDownStyle: DropDown
假设你的组合有这些项目,那么你必须将它们添加到autocompletecustomsource
ComboBox1.Items.Add("10")
ComboBox1.Items.Add("92")
ComboBox1.Items.Add("9000")
ComboBox1.Items.Add("9001")
ComboBox1.AutoCompleteCustomSource.Add("10")
ComboBox1.AutoCompleteCustomSource.Add("92")
ComboBox1.AutoCompleteCustomSource.Add("9000")
ComboBox1.AutoCompleteCustomSource.Add("9001")
ComboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
答案 1 :(得分:1)
是的,这可以通过AutoCompleteMode
和AutoComplete
实现,如下所示:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
ComboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
'Add some options
ComboBox1.AutoCompleteCustomSource.Add("ABC")
ComboBox1.AutoCompleteCustomSource.Add("BCD")
ComboBox1.AutoCompleteCustomSource.Add("CDE")
End Sub
'Add ComboBox1.Text to AutoCompleteCustomSource collection when leaving ComboBox
Private Sub ComboBox1_Leave(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ComboBox1.Leave
ComboBox1.AutoCompleteCustomSource.Add(ComboBox1.Text)
End Sub
End Class
阅读AutoCompleteMode Enumeration了解详情。