How Add suggestion to TextBox Text in C#
How to Add Autocomplete to TextBox in C#
How to Add Autocomplete to TextBox in C#
Suggestion box to search field will simplify the user while searching for a person or product from database...In c# it is very simple to achieve autocomplete. use the below code in Textbox MouseClick Event or Create a method to write code and call it in the MouseClick Event. I am Doing this by creating a method named AppendSuggestion() follow the steps below...
1. Create method public void AppendSuggestion()
public void AppendSuggestion()
{
// create list of sujjestion
string [] suglist={"sabeer","shihab","shameen","shafi","hashim"};
//Create and initialise object source for AutocompleteStringCollection
var source = new AutoCompleteStringCollection();
source.AddRange(suglist);
txtboxSearch.AutoCompleteCustomSource = source;
txtboxSearch.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
txtboxSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
{
// create list of sujjestion
string [] suglist={"sabeer","shihab","shameen","shafi","hashim"};
//Create and initialise object source for AutocompleteStringCollection
var source = new AutoCompleteStringCollection();
source.AddRange(suglist);
txtboxSearch.AutoCompleteCustomSource = source;
txtboxSearch.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
txtboxSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
* txtboxSearch is the TextBox object we are entering the serch query.
2. Now Create Event MouseClick for txtboxSearch ...and call the method AppendSuggestion() in it....Thats it...Done..!!
// TextBox Search Click Event
private void txtboxSearch_MouseClick(object sender, MouseEventArgs e)
{
AppendSuggestion();
}
private void txtboxSearch_MouseClick(object sender, MouseEventArgs e)
{
AppendSuggestion();
}