Winforms Textbox Autocomplete in c# using Linq

xyzDataContext dc = new xyzDataContext();
AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();
var query = from c in dc.Clients
            select c.Company;
foreach (String comp in query)
{
      namesCollection.Add(comp);
}
tBoxCompany.AutoCompleteSource = AutoCompleteSource.CustomSource;
tBoxCompany.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
tBoxCompany.AutoCompleteCustomSource = namesCollection;

Result =>

AutoCompleteMode accept thoose values :

External link :
AutoComplete TextBox In WinForms
AutoComplete TextBox in C#

2 Comments on “Winforms Textbox Autocomplete in c# using Linq

  1. Jack says:

    You, my friend, are a genius.

    Nobody else on the interwebs even had a clue on how to achieve this little gem of a feature involving linq.

    Thank you so much!

    1. Mike says:

      Thanks :)

      I have search the web for a solution because I knew (deep inside me) that something should exists…

      Found some sources and sample, then i made it from my own and ‘voila’…

      Happy that my experience bring you some help.

      Mike


Leave a Reply