Dynamic autocomplete combobox

A

Andrus

If I press Windows+R key in Windows and type some letters,
Autocomplete list shows possible choices.

I want to implement similar thing in winforms application:

when I type first letters from customer name,autocomplete list for customers
starting with this same should apper.
Since there a large amout of customer names, I must run query in database to
find 20 nearest matches.
Database query must executed if no key is pressed for 3 seconds.

Any sample code how to implement this ?


Andrus.
 
N

Nicholas Paldino [.NET/C# MVP]

Andrus,

Take a look at the AutoCompleteCustomSource property on the TextBox or
ComboBox (or ToolStripTextBox/ToolStripComboBox) classes. It will allow you
to set the source of the data that is used for auto complete on those
controls (you will have to set the AutoCompleteMode and AutoCompleteSource
properties as well to get the specific behavior you want).
 
A

Andrus

Nicholas,
Take a look at the AutoCompleteCustomSource property on the TextBox or
ComboBox (or ToolStripTextBox/ToolStripComboBox) classes. It will allow
you to set the source of the data that is used for auto complete on those
controls (you will have to set the AutoCompleteMode and AutoCompleteSource
properties as well to get the specific behavior you want).

Thank you.
I have tried AutoComplete with Winforms combobox control.
I have no idea how to populate autocomplete dropdown list properly after
search characters are entered/modified.

If user enters some characters rapidly there is it probably not reasonable
to execute sql query over internet to get matching items.
Should I create timer and subscribe to timer event from combobox method ?
Should I use Combobox OnKeydown method to create timer ?
How to force autocomplete menu to appear only after 5 sec, when data
retrieval from database called from timer is executed ?

Where to find sample code for this ?

Andrus.
 
R

RobinS

If there are really so many values that you can't put all of them in a
combobox (like thousands), I'd find another way to do it. You could put a
filtering combobox first, then the customer combobox next to it, with the
filter filled with the letters from A to Z, then load the customer combobox
based on the filter. If THAT filtered list is small enough, you could make
it an autocomplete list.

Put a list of linklabels across the screen for each letter of the alphabet,
and when they click on one, load the customer combobox.

If you want them to be able to filter on more than one letter, put a textbox
on the left with a button called something like "GetCustomers" and load the
customer combobox based on that.

Capture the keypress event, restart a stopwatch every time they click a key
in the combobox, and when they stop for more than a couple of seconds, run
the query. This, of course, would be the most difficult.

You have to decide what it's worth, and what your customers are willing to
pay for.

RobinS.
GoldMail, Inc.
----------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top