Reputation: 737
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.
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.
Is this possible? Thanks in advance.
Upvotes: 4
Views: 9985
Reputation: 34846
Yes, this is possible via the AutoCompleteMode
and AutoComplete
, like this:
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 Enumeration for more information.
Read AutoCompleteSource Enumeration for more information.
Upvotes: 1
Reputation: 4081
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
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
Upvotes: 4