Home > DeveloperSection > Articles > Auto complete text in Combo Box

Auto complete text in Combo Box

C# C# 
2 Comment(s)
 3242  View(s)
Rate this:

Auto complete text in Combo Box

Here we are going to create AutoComplete ComboBox and we are showing you how to create it.
First of all what is AutoComplete, suppose ComboBox contains more than 200 records and user will have to scroll down or he should write full name but if ComboBox is AutoComplete then it will pick the name instantly.

Like ComboBox contains name of the user “Peterson”, when user will type name “pet” then it will pick full name “Peterson” , here below We are going to show you in screenshot so you will understand in better way.

Screen shot


Here is the code


This code is written in ComboBox KeyUp event as we have to check after every new character is typed.


private void comboBox1_KeyUp(object sender, KeyEventArgs e)


            int index;

            string actual;

            string found;


            // Do nothing for certain keys, such as navigation keys.

            if ((e.KeyCode == Keys.Back) ||

            (e.KeyCode == Keys.Left) ||

            (e.KeyCode == Keys.Right) ||

            (e.KeyCode == Keys.Up) ||

            (e.KeyCode == Keys.Down) ||

            (e.KeyCode == Keys.Delete) ||

            (e.KeyCode == Keys.PageUp) ||

            (e.KeyCode == Keys.PageDown) ||

            (e.KeyCode == Keys.Home) ||

            (e.KeyCode == Keys.End))





            // Store the actual text that has been typed.

            actual = this.comboBox1.Text;


            // Find the first match for the typed value.

            index = this.comboBox1.FindString(actual);


            // Get the text of the first match.

            if (index > -1)


                found = this.comboBox1.Items[index].ToString();


                // Select this item from the list.

                this.comboBox1.SelectedIndex = index;


                // Select the portion of the text that was automatically

                // added so that additional typing replaces it.

                this.comboBox1.SelectionStart = actual.Length;

                this.comboBox1.SelectionLength = found.Length;





By Manmohan Jha on   4 years ago
Hi Sir,

Plz implement scroll system in this code...
Ex:-Matched word scroll... 


Auto complete text in Combo Box

By Haider M Rizvi on   4 years ago

For implementing Auto complete functionality in Combobox, all you have to do is to set two properties of the combobox.
  • AutoCompleteMode
  • AutoCompleteSource

This will do the work for you.

Don't want to miss updates? Please click the below button!

Follow MindStick