AutoComplete Feature in Windows Form Application

By Nitesh Luharuka Nov 07 2012
In this blog you will learn how to use AutoComplete feature in Windows Form Application
    • Like
    • Love It
    • Awesome
    • Interesting
    • It's Okay
    • Thumbs Down
  • 5.2k
  • 0

We use AutoComplete feature in our websites many times. Wonder, how we can achieve the same in windows forms.

Let us build it today. We will do it step by step as mentioned below

  1. Open Visual Studio and create a new Windows Form Application Project and name it "AutoCompleter"

  2. Drag and Add a TextBox to the form.

  3. Double Click the form to create the Form_Load() Event Handler.

    private void Form1_Load(object sender, EventArgs e)
  4. Write the below code in the Event Handler.

    SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=tempdb;Integrated Security=True;Pooling=False");
    SqlCommand cmd = new SqlCommand("Select distinct [name] from [IPLTeams] order by [name] ASC", con);
    SqlDataReader re = cmd.ExecuteReader();
    AutoCompleteStringCollection coll = new AutoCompleteStringCollection();
    textBox1.AutoCompleteCustomSource = coll;
  5. Build the project and Execute.

Hope you find it useful. Let me know your thoughts via Comments.