AutoComplete Textbox in Windows Application


Introduction :
This code demonstrates the use of AutoComplete Textbox in Windows Application the same way as we use Ajax in Web Applications.

Pre-requisites :

Textbox properties to be set for achieving this :
1) AutoComplete Mode - You can select any from it, either Suggest/Append/SuggestAppend (In my case I have taken Suggest here)
2) AutoCompleteSource - Set it as CustomSource
3) AutoCompleteCustomSource - Its a collection

As shown in the Figure take a form with a textbox named txtname. Here I am fetching names from the database.

public partial class Form9 : Form


public string strConnection = ConfigurationManager.ConnectionStrings["test1"].ConnectionString;

AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();

public Form9()




private void Form9_Load(object sender, EventArgs e)


OdbcDataReader dReader;

OdbcConnection conn = new

conn.ConnectionString = strConnection;

OdbcCommand cmd = new OdbcCommand();

cmd.Connection = conn;

cmd.CommandType = CommandType.Text;

cmd.CommandText = "Select distinct name from sample order by name";


dReader = cmd.ExecuteReader();

if (dReader.HasRows == true)


while (dReader.Read())





MessageBox.Show("Data not found");



txtname.AutoCompleteMode = AutoCompleteMode.Suggest;

txtname.AutoCompleteSource = AutoCompleteSource.CustomSource;

txtname.AutoCompleteCustomSource = namesCollection;





Author: Mrs. Meetu Choudhary Nanda28 Sep 2009 Member Level: Gold   Points : 1

Cool Presentation, and good concept

++Thanks and Regards
Meetu Choudhary
Site coordinator

Author: Deepika Haridas30 Sep 2009 Member Level: Gold   Points : 1

Thank you Meetu...

Thanks & Regards,

Author: sathish.j30 Sep 2013 Member Level: Bronze   Points : 0

Simple and Excellent article. Thank you so much.

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: