TextBox AutoComplete

I made a form with a textbox.

This textbox is for country name and I wanted to help input with AutoComplete.

 

So I coded.

foreach (M_Country country in M_CountryList)
{
    txtCountry.AutoCompleteCustomSource.Add(country.Name);
}

 

But it was very slow.

 

First I thought M_CountryList (which is VisiCoolStorage List object) was not fetching the data properly and seeking data slowly.

But then it appeard that reading data isn't slow at all!

The problem was adding items to the customSource.

Although the control is not displayed yet, somehow it takes quite a long time to add many items into it.

 

Solution:

AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
foreach (M_Country country in Program.M_CountryList)
{
    sc.Add(country.Name);
}
txtCountry.AutoCompleteCustomSource = sc;

 

Creating a non-visible collection to add items and then assign the collection to AutoCompleteCustomSource.

Simple and fast.

 

Good!!!