Combo box fill as you type

Impi

Member
Joined
Nov 13, 2008
Messages
5
Programming Experience
Beginner
Hi Guys,

New at all this so take it easy.....

I have a combo box and want to give the user the possible values as he types. Normally you would just add all the items to the combo box and the framework does the rest. My problem is that it takes 15-30 seconds to fill the combo box because initially it could have up to a million possibilities. So what I want to do is: When the user type the char "5" then I want to list on the fly all values for "5", is he then adds a "1" it will then be "51" and all possible values. Unless there is a better way... I'll leave it to you brainies

Thanks
 
Maybe you can use a text box and an AutoCompleteStringCollection and fill the collection with the correct values when the user click a refresh button next to the text box. The button would enable when there are at least 2 characters typed in the textbox and you would fill the autocomplete collection with the values that match only. Then you would watch at each TextChanged event if the first 2 letters have changed and clear the list if it does.

Or you could start filling the AutoCompleteStringCollection in a BackgroundWorker and assign it to the text box when the worker finishes filling it. The user would spend a few seconds without any values in the list, then they would appear to help him out. You can set some visual cue for the user to know it's working.

You could also use both techniques so the user can type stuff and when he does, you start a background worker that creates a list of the available possibilities. He'd just have to wait 15 seconds to see the possibilities, but if he knows how it begins, he can type the first few letters and you will halt any previous list retrieval to start again for the possibilities that begin like what he entered.

Then you'd add some calculation on TextChanged to see if the new value in the textbox begins with that used to retrieve the current list of possibilities so you refresh the list only when the current list does not contain all the possibilities for the current text. This way, if the user lets the list fill at any point and starts appending characters to the value, the list won't refresh needlessly. But if the user types something that doesn't have its possibilities in the list, the list is refreshed. Without you having to loop through the list to see if it does.

I hope I was clear, I usually start talking Chinese when I get those bright ideas! Ask if you don't understand! :)
 

Latest posts

Back
Top