i want to create a suggestion box like in google. I want the data from database in suggestion box and i have created a dataset .
i looked through all the properties of textbox and set AutoCompleteMode=SuggestAppend , AutoCompleteSource=CustomSource , and gave few values at AutoCompleteCustomSource (collection)
and it actually worked. What should i do to do the same using data from database?
Add a comment
|
1 Answer
take out the data from your db table, prepare a Collection and bind it to your controls AutoCompleteCustomSource through code.
see the code below:
public void BindAutoCompleteList(DataTable myDataTable)
{
AutoCompleteStringCollection acDataSource= new
AutoCompleteStringCollection();
foreach (DataRow row in myDataTable.Rows)
{
acDataSource.Add(row.Cells[0].Value.ToString());
}
txtBoxAuto.Clear();
txtBoxAuto.AutoCompleteMode = AutoCompleteMode.Suggest;
txtBoxAuto.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtBoxAuto.AutoCompleteCustomSource = acDataSource;
}
and call this BindAutoCompleteList() in the Form's constructor or any location suitable to your app.
where myDataTable consists of your db table rows