47

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".

TylerH
  • 20,799
  • 66
  • 75
  • 101
prabhuK2k
  • 2,188
  • 1
  • 19
  • 20
  • 1
    Make the DropDownStyle 'DropDown' – Dan Apr 17 '12 at 08:52
  • 1
    ...and AutoCompletStyle 'Suggest' – Dan Apr 17 '12 at 08:57
  • It's unclear if you _want_ the combobox to jump to options starting with "S" if you type "As" or if that's how it currently works, and you want it to _instead_ jump to options starting with "As". If you want the latter (jump to "As" after typing "As") this is called "incremental search". – TylerH Jun 09 '22 at 15:53

2 Answers2

92
comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
prabhuK2k
  • 2,188
  • 1
  • 19
  • 20
  • 3
    You can also do this with a `DropDownStyle` of `DropDownList` using these AutoComplete options - it just won't explicitly show the user the keys that they've typed thus far. However, it's nice when you want to keep the `ComboBox.Items` immutable. – Derek W Mar 21 '14 at 16:53
  • 7
    You should first set the Source and then set the Mode, otherwise it throws a NotSupportedException. Then it works perfectly – Gaeburider May 08 '14 at 13:48
  • 4
    This is called "incremental combobox search", FYI. – Baz Guvenkaya Aug 20 '18 at 06:06
  • 1
    If you use DropDownList as your DropDownStyle, you need to type relatively quickly for the subsequent letters to continue filtering. You can't type a first letter, look and think, then type the second letter. The combobox will take the second letter as the start of a brand new search. – Girl Spider Jan 07 '21 at 16:19
-2

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.

Likurg
  • 2,742
  • 17
  • 22