The snippet below shows how to do auto complete for text box.
Note that “textBox1” is a control in the form.
using System; using System.Data; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { textBox1.AutoCompleteMode = AutoCompleteMode.Suggest; textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; AutoCompleteStringCollection DataCollection = new AutoCompleteStringCollection(); AddItems(DataCollection); textBox1.AutoCompleteCustomSource = DataCollection; } public void AddItems(AutoCompleteStringCollection col) { col.Add("Ganesh"); col.Add("Shashi"); col.Add("Rajani"); col.Add("Kyle"); col.Add("Connar"); col.Add("Stephanie"); col.Add("Claire"); col.Add("Jerrall"); } private void txtSearchValue_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Enter) { MessageBox.Show("X"); } } } }
Note that there is no such thing as chosen item Event for a TextBox for AutoComplete. In the snippet, what I have done is to add a key down event to your TextBox; in which I have added and IF statement to verify if the enter key was pressed (clicking on a suggested link is the same as pressing enter).