prabhuK2k
prabhuK2k

Reputation: 2238

How to narrow the options list in a comboBox by typing - incremental search

I have a combobox that has hundreds item in it. User must be able to type the text into the combobox. While the user is typing the text, the item that starting with the typed value must be selected or listed. The user must be able type continuously. My ComboBox DropDownStyle is DropDownList

E.g: While selecting a name in comboBox by typing, it only allows one letter. So if I type "A" it will jump to the first letter starting with "A". When I type continuously the combo box selected item changes according to the current keypress. If I press "As", combobox viewing the items starting with "s".

Upvotes: 49

Views: 76090

Answers (2)

prabhuK2k
prabhuK2k

Reputation: 2238

comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;

Upvotes: 95

Likurg
Likurg

Reputation: 2760

You will have to hook up to the TextChanged event. When the text changes, filter the list (using a DataView) and take the text of the first result, setting the text of the combo box to that. You would have to have a check in your handler of course, to determine whether or not to handle the event (when you change the text, another TextChanged event would be fired). Of course, you also want to highlight the text that they typed in, and place the caret at the appropriate position.

Upvotes: -2

Related Questions