Question Autocomplete Listbox

tim8w

Well-known member
Joined
Sep 8, 2020
Messages
133
Programming Experience
10+
Is there a way to add Autocomplete like ComboBox has to the ListBox control?
 
You are mixing UI paradigms. The point of a ListBox is to show a user all the choices and they click on their choice. They should not have to type. If you want to take keypresses, the classic ListBox will take you the first thing on the ListBox that matches that keypress.

If you say, "but there's too many items in the ListBox", then that means you are using the wrong UI. You can't expect a user to reasonable pick from a ListBox that has more than 100 items as a rule of thumb. Don't use a ListBox. Use a ComboBox or a TextBox with autocomplete instead.

You are asking on the Windows Forms subforum. Note the "Windows" part. That means you need to follow the Windows UI guidelines. Don't make up your own UI and cause Windows critics to have more ammunition about inconsistent Windows UI.
 
Auto-complete with a ListBox makes no sense because there's nowhere to type. That's why auto-complete only exists on a TextBox and a ComboBox and, in the latter case, only when you can type directly into it. Just like a ComboBox when DropDownStyle is set to DropDownList, a ListBox will select the next item starting with that character when you press a key but it won't string characters together because they aren't stored anywhere.

What you can do is use a ComboBox with DropDownStyle set to Simple. That produces a somewhat hybrid UI, i.e. the contents of the list is always displayed like a ListBox but you have a data entry field at the top like a "regular" ComboBox. You can then set and use the auto-complete fields in the same way as when DropDownStyle is set to DropDown. What you can't do is select multiple items like you can in a ListBox but I'm assuming that you don't want to any because auto-complete would make no sense in that scenario.
 
Back
Top Bottom