1
Answer

Autocomplete any character using textbox in C#

Bang Lam

Bang Lam

10y
735
1
Hi all,
 
I have  a datatable that include the data output as following:
{Apple, April, Orange, Lemon}
 
Currently, I'm using autocomplete method as below:
 
AutoCompleteStringCollection source = new AutoCompleteStringCollection(); 
DataTable dt = DataServiceMySQL.SearchCommandTextDataTable("SELECT `name` FROM `product`");
 
for (int i = 0; i < dt.Rows.Count; i++)
{
source.Add(dt.Rows[i][0].ToString());
 
txtProduct.AutoCompleteMode = AutoCompleteMode.Suggest;
txtProduct.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtProduct.AutoCompleteCustomSource = source; 
 
But this method when you use the filter method, data output such as the following example:
Ex: when you input character 'a' then the data output: Apple and April.
     when you input chacter 'o' then the data output: Orange.
     when you input chacter 'l' then the data output: Lemon.
But I want to inout character 'e' then the data output: Apple, Orange.
 
Please help and thank you very much ^_^
 
Answers (1)