1

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?

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.