Click here to Skip to main content
15,886,780 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hello,

I want to create an auto complete textbox based on values from a database. If the user enters any letter, then that letter is matched to a value in the database and then is displayed. I can do this in a web application but I am having difficulty with it in a Windows form application




Thank You!!
Posted
Updated 22-Feb-12 23:50pm
v2
Comments
Slacker007 23-Feb-12 5:51am    
Edits: formatting and readability.

 
Share this answer
 
Comments
Hifni Shahzard 27-Jun-12 1:57am    
The above Link is dead. For the above scenario, the basic is each time a text is being entered the OnTextChanged Event fires and will require multiple DB hits to fetch the result. What would be the feasible solution other than to avoid multiple DB hits?
On Form Load call the Textbox autocomplete method "autocompleteData".

public void autocompleteData()
{
//SuggestStrings will have the logic to return array of strings either from cache/db
var CurrentuserId = CloudKaseWSClient.GetUserDetail(tokenUsr, tokenPasswd, Username);
List<string> l = new List<string>();
var SearchResults = ("Select Database Query").ToList();
foreach (var i in SearchResults)
{
l.Add(i.name);
}
string[] arr = l.ToArray();
AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
collection.AddRange(arr);

txtSearchUser.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
txtSearchUser.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtSearchUser.AutoCompleteCustomSource = collection;
}


OR You want to set static data for AutoComplete Textbox than you have to set In Design view for Textbox property of AutocompleteMode to set SuggestAppend,AutocompleteSource to set CustomSource and add static value inAutocompleteCustomSource.

I hope this solution helps to you..
Happy Coding.:)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900