December 5, 2010

C# - Auto Complete Text box


The auto complete feature of the text box allows the user to enter part of the details in the text box and complete the remaining automatically. Say for example a country text box, which will fill the entry India when first two letters are typed. There is two important way we can save the typing. One is auto complete by filling the remaining text and another one is providing a suggestion in the form a matching list to pick the correct one.

In this article, we will design the auto complete text box with above said two kinds of an auto-complete feature. This article uses only form designer and there is no added.

Form design

Create a Visual C# Windows application using VS2005. Add two label and two text boxes. Use the following picture for reference:

A: For the first text box set the Following Properties:

  1. Set CustomSource value for the property Autocompletesource
  2. Set Append value for the property AutoCompleteMode
  3. Set the below-specified value for the Property AutoCompleteCustomSource
Mahesh Chand
Sivaraman Dhamodaran
Praveen Kumar
Hashit viyas
Dentin Joy
Suthish Nair
Sure Meenakshi
Mike Gold

B: For the second text box set the same property and values as specified above with the exception that AutoCompleteMode be set to Suggest.

Run the Application and test

1) Run the Application
2) In the First text box type only the letter S

Note that the auto complete (Append) tries to fill the textbox value based on the alphabetical order.
3) Now type U and then T your intention is to get Suthish Nair in the text box.
4) Now go to the second text box and experiment it yourself.

Note: The attached sample is created in VS2005.

Source Code: Download

No comments:

Post a Comment

Leave your comment(s) here.

Like this site? Tell it to your Friend :)