How to integrate AutoComplete Feature in Winforms ?

In one of my previous article AutoComplete is an ASP.NET using Ajax autocomplete extender ,I explained how to create AutoComplete TextBox in ASP .NET using AJAX , in this example i am achieving the same in Windows forms application . For this i’ve created a Autocomplete string collection containing names which will be shown in textbox as suggestions.

How to integrate AutoComplete Feature in Winforms ?

Both TextBox and ComboBox controls in many applications provide suggestions as we type, and it was a pain to accomplish this in previous versions of Microsoft’s development tools. The three properties that manage this behaviour AutoCompleteMode, AutoCompleteSource, and AutoCompleteCustomSource.

1. AutoCompleteMode – None is the default, but assuming that you’ve supplied a list of values, Append simply appends the first item that matches what you’ve typed so far; Suggest provides a drop-down list with a list of values that match what you’ve typed, and SuggestAppend displays the list, and when you press Enter or Tab to move focus from the control, appends the selected value into the control’s contents.

2. AutoCompleteSource – You can choose from None (the default); FileSystem (uses the file system); FileSystemDirectories (uses only folders within the file system); HistoryList (uses your history list); or RecentlyUsedList (uses your most recently used URLs). In addition, you can select CustomSource, which allows you to specify a string collection in the AutoCompleteCustomSource property. ComboBox controls allow you to specify ListItems for the AutoCompleteSource property, which uses the items in the control’s list for its suggestion list.

3. AutoCompleteCustomSource – Self explanatory. Simple Example

textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox1.AutoCompleteCustomSource.AddRange(new string[] {
      "senthil", "senthil kumar", "senthil kumar b",
      "christ college", "sandy",
      "cp" });

Now, when you run the project and enter “s”into the text box, you can select one of the states that begins with “s” With the addition of these new properties, searching within ComboBox and
TextBox controls has improved drastically in Visual Studio 2005 and made my job even easier.

    2 Comments

  1. imtiyaz
    February 19, 2011
    Reply

    thanks, very nice stuff

  2. Shankar
    March 30, 2011
    Reply

    Hi,

    I need to use that AutoCompleteMode in WindowsMobile Application(vs2008) for combobox.Is there any solution for this?Reply me.
    Thank you.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This blog post will guide you through several effective methods to troubleshoot and resolve the issue of Microsoft Edge not...
Windows 11 offers a range of audio enhancements that can enrich your listening experience. These enhancements include features like virtual...
Windows 11 brings a fresh and visually stunning design to your desktop, and one of the standout features is the...