FAtechs is a Web Site where you can find a lot of things related to tech and Education. Our Posts are mostly about Programming, Information, Technology,Software, Reviews & Everything You need to Know. You can also find Books and Novels here. Your appreciation and criticism will be welcomed.

How to Use Auto fill in ComboBox in C# , Intellisense in C#, Step by Step Tutorial

Auto Fill or Intellisense in C#:

I know you are curious about intellisense in C# because now a days about all big application uses intellisense including Softwares like Visual Studio, SQL Server Web Sites like Facebook in their Search Bar or any other Search Engine uses in their Search Bar.

Today you will learn easily to make use of intellisense in your Windows Form applications. It is easy to use intellisense in a Combo Box and Auto Fills the Combo Box when User enter the Starting Keywords.

Steps to Add Auto Fill / Intellisense in C#:

First of all, Add a Combo Box From the Tool Box in Windows Form Application as shown below, drag the Combo box to win Form Application to use this.

Put some Values like names in the items of that Combo Box

A Dialog will Open, Enter one name per line

Write Following Code in this event:

private void comboBox1_KeyUp(object sender, KeyEventArgs e)

{

int i;

string original;

string word_founded;

// eliminate the function 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))

{

return;

}

original = this.comboBox1.Text; // Store the original text that user types

i = this.comboBox1.FindString(original); // Find the first match for the typed value.

if (i > -1)// first match.

{

word_founded = this.comboBox1.Items[i].ToString();

this.comboBox1.SelectedIndex = i; // Select this item.

this.comboBox1.SelectionStart = original.Length; // this code select the part of word that was added automatically and replaces it.

this.comboBox1.SelectionLength = word_founded.Length;

}

}

Now Run the Program and check the Output by writing the initial letter of any name that has been added by you.