Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Dynamic autocomplete combobox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrus - 22 Feb 2008 18:16 GMT
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.
Nicholas Paldino [.NET/C# MVP] - 22 Feb 2008 19:13 GMT
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).

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> If I press Windows+R key in Windows and type some letters,
> Autocomplete list shows possible choices.
[quoted text clipped - 10 lines]
>
> Andrus.
Andrus - 22 Feb 2008 19:56 GMT
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.
RobinS - 24 Feb 2008 18:48 GMT
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.
----------------------------------
> Nicholas,
>
[quoted text clipped - 20 lines]
>
> Andrus.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.