In my application a ListBox is filled after a user puts more than two characters into a textBox.
If there is a lot to fill into the ListBox, the user has to wait until the ListBox is completely filled before is able to continue his input.
Now I need a solution to fill the ListBox without blocking the UI, so I would like to use a background worker to solve this.
—- Original Version —–
In my application I fill a ListBox when the user puts in more then two characters into a textBox.
The ListBox fills with results and after this, the user is able to put in more characters.
My problem is the following behaviour: The user is only able to put in the next char after the whole ListBox is filled with all entries. If there are a lot of results the user has to wait until he is able to continue.
I would like to have the following behaviour: If the user puts in a char, the filling of the ListBox should stop and build the list for the new input.
I thought about sth. like:
[PSEUDO-CODE]
loop over results {
if (UserInput) { // <-- GetKeyState()?
break
}
AddOneItemToListBox
}
[/PSEUDO-CODE]
I thought about sth. like GetKeyState() but I think there should be a more elegant way (perhaps a control or another technology I don’t know about ATM).
P.S.: Currently I’m looking for a solution with .Net2.0, but if there is a technology inside a later version of .Net I would also be glad for a short hint (just for my information).
You can fill the the ListBox within a
BackgroundWorker(don’t forget to call theAdd()method withBeginInvoke()). In this case the user can already interact with the GUI while the box will be filled.If the user adds something to the box on himself you can stop the autofill by calling
worker.CancelAsnyc().Update (compatible with VS 2005)
Unfortunately i don’t have VS2005 to try it out, but i removed all the fancy lambda, etc. stuff.
Just a simple sample for starting: