When you have a requirement for combo box control like: when user types some text/number then combo box should display/select value as per user typing the characters from keyboard.
Ex: If Combo Box having following items
ComboBox1.Items.Add("ABC123")
ComboBox1.Items.Add("AABC123")
ComboBox1.Items.Add("AAABC123")
ComboBox1.Items.Add("AAAABC123")
ComboBox1.Items.Add("CCCEF123")
ComboBox1.Items.Add("1123ABC")
ComboBox1.Items.Add("2234BCD")
ComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
and requirement is when user type in the combo box the relative text should display
Ex: When user type "A" then combo box should select "ABC123" value from the list
When user type "AA" then combo box should select "AABCD123" value from the list
When user type "AAA" then combo box should select "AAABC123" value from the list
etc.
To achieve above requirements, very simple in .NET to use "ComboBox1.AutoCompleteMode" property, it has 4 mode and default is "None"
This Mode will append the value as user type the characters one by one and select the nearest value in the combo box and also will open (Drop) the combo box to suggest the other nearest possible value present in the combo box
4) AutoCompleteMode.None (Default)
This Mode will select the nearest value in the combo box when user type ONLY first characher in the combo box
1 comment:
A sample...C# Autocomplete Combobox
Ling
Post a Comment