I have a textbox used to type in strings and display all the avaiable results in this textbox.The current code like follows:
private void Form_Load(object sender, EventArgs e)
{
TextBox.AutoCompleteMode = AutoCompleteMode.Suggest;
TextBox.AutoCompleteSource = AutoCompeteSource.CustomSource;
}
private void TextBox_TextChanged(object sender, EventArgs e)
{
TextBox t = sender as TextBox;
if(t != null)
{
if(t.Text.Length > = 1)
{
AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
collection.AddRange(s.Name);
this.TextBox.AutoCompleteCustomSource = collection;
}
}
}
In the above code, s.Name
is the source of all the strings I want to search. It shall work only I correctly typed the first letter of the string. For example. One of the s.Name
may be ABCDEF
I want it avaiable when I type any sub string of it, maybe EF
or BC
but not only AB
or ABC
. How should I do this? Thanks!