Auto complete TextBox in C#


An Autocomplete Textbox is a must have for a commercial application, it can bring user friendly features to you application.
Lets learn how to add a Auto complete feature, here is the plan


Code poet’s steps

  1. First we make up the Autocomplete string collection.
    1. Create AutoCompleteStringCollection
    2. Add items to the collection.
  2. Set Autocomplete mode
  3. Set Auto complete source as custom source
  4. Set auto complete custom source as Autocomplete string collection.
  5. That is all

Code

AutoCompleteStringCollection a = new AutoCompleteStringCollection();
            a.Add(“Babool”);
            a.Add(“Ice Bowl”);
            a.Add(“Mango”);
            a.Add(“Mangoose”);
            a.Add(“Chiken”);
            a.Add(“Fruits”);
            textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
            textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            textBox1.AutoCompleteCustomSource = a;

As you see you can just type the letters Man  and a new list will populate, as result of the AutoCompleteMode.Suggest code, can replace it with append or appendSuggest which will automatically complete text as you type.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.