Skip to content
Advertisement

Winforms, can I use a text box here instead of a combobox? (dropdown list with over 15k options)

For the last few weeks I’ve been building a product demo for work which includes a winform to enter new customer enquiry information. One of the form elements is a text box which, for the sake of ease, I haven’t imposed any validation on so far. However, I now need to make it so that the user can only enter a valid location from an sql database table (containing around 15k streets).

I’m still quite new to C# programming. My first thought was that I should change my text box to a combobox but I seem to remember that when you click on a combobox all the options in the list appear before you’ve typed anything. Since our computers are slow and there’s so many options, I don’t really want to flood the screen so I was wondering if there was a way I could continue using my text box and onkeypress (probably the tab key) a dialogue pops up with all the closest matches from the list, prompting the user to select a valid option?

If not, is there a way to stop my combobox from showing the option list until prompted?

Advertisement

Answer

I would not think a combobox is not well suited for that many items.

The way I have approach this is to use a separate list view to show matches. You could probably put matches in a drop-down style borderless window, but I find that more complex and may be difficult to make the interaction work well. I would just have the streets in a separate list view control and apply a filter to that.

Make sure the view is resizable, I find it very frustrating when working with old window controls where the list is tiny due to it being written for 640×480 screens, and does not allow resizeing.

Keep performance in mind, when searching with each key-press you might want to fetch all records and do the search in memory rather than making a sql query for each key.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement