VB.net ComboBox 在输入时自动下拉
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18670245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.net ComboBox auto drop down on input
提问by Marc Intes
I want to create a ComboBox that automaitcally drops down the words containing the letter based on the input. My dropdownstyle is dropdown so the combobox has an input field.
我想创建一个 ComboBox,它会根据输入自动删除包含字母的单词。我的下拉样式是下拉,所以组合框有一个输入字段。
For example i would input the letter A or a I want the ComboBox to automatically dropdown the words which contains the letter A or a. The contents of the ComboBox are being set by myself manually.
例如,我会输入字母 A 或 a 我希望 ComboBox 自动下拉包含字母 A 或 a 的单词。ComboBox 的内容是我自己手动设置的。
Is this possible? Thanks in advance.
这可能吗?提前致谢。
采纳答案by Bibhu
You have to set these
你必须设置这些
AutoCompleteMode: SuggestAppend
AutoCompleteSource: ListItems
DropDownStyle: DropDown
Suppose your combo has these items then you have to add them to the autocompletecustomsource also
假设您的组合包含这些项目,那么您还必须将它们添加到 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
回答by Karl Anderson
Yes, this is possible via the AutoCompleteModeand AutoComplete, like this:
是的,这可以通过AutoCompleteModeand 实现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
Read AutoCompleteMode Enumerationfor more information.
阅读AutoCompleteMode 枚举以获取更多信息。
Read AutoCompleteSource Enumerationfor more information.
阅读AutoCompleteSource 枚举以获取更多信息。

