Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a C# Windows Form DropDownList to behave like a browser drop down list?

I have a ComboBox in DropDownList mode. Say the contents are:

1
2
5
91
92
99
205

In the Forms application, I want to be able to focus on the control and type 205 and have it select 205. Instead, I press 2 - it jumps to 2. I press 0, nothing starts with 0, so it stays on 2. I press 5, it jumps to 5. It's only looking at the last key I pressed.

Same if I type 99, it jumps to the first 9 match - 91, then to the second 9 match - 92. But I wanted it to go to 99.

On the other hand, in any browser if you are on a dropdown and type in a sequence of characters, it will consider them all together and jump to a full match. (Same behavior in Windows folders if you type a file name.) The sequence usually resets after a few seconds of no typing.

How can I get my forms dropdown to behave like a browser dropdown?

like image 657
ovinophile Avatar asked Apr 05 '11 21:04

ovinophile


2 Answers

Set the AutoCompleteMode to Suggest, AutoCompleteSource to ListItems and the Style to DropDownList.

like image 177
Cwoo Avatar answered Sep 28 '22 03:09

Cwoo


I would also add that you need to set the "FlatStyle" property to "Popup" to make it more like the Web combobox.

like image 33
Jay Jay Johnstan Avatar answered Sep 28 '22 04:09

Jay Jay Johnstan