user3378112
user3378112

Reputation: 27

How to fill combobox with country names in a C# windows application

I tried following code to fill combobox with country names

private void PopulateCountryComboBox()
{
            RegionInfo country = new RegionInfo(new CultureInfo("en-US", false).LCID);
            List countryNames = new List();
            foreach (CultureInfo cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                country = new RegionInfo(new CultureInfo(cul.Name, false).LCID);
                countryNames.Add(country.DisplayName.ToString());
            }

            IEnumerable nameAdded = countryNames.OrderBy(names => names).Distinct();

            foreach (string item in nameAdded)
            {
                cmbcountry.Items.Add(item);

            }
}

I am getting following error

Using the generic type 'System.Collections.Generic.List' requires 1 type arguments

Upvotes: 3

Views: 2539

Answers (2)

Sumeshk
Sumeshk

Reputation: 1988

Modify

  RegionInfo country = new RegionInfo(new CultureInfo("en-US", false).LCID);
  List countryNames = new List();

as

RegionInfo country = new RegionInfo(new CultureInfo("en-US", false).LCID);
  List<string> countryNames = new List<string>();

this may solve your issue

Upvotes: 1

Baldrick
Baldrick

Reputation: 11840

List<T> is a generic collection. You need to supply what type it's going to be a list of.

Try:

List<string> countryNames = new List<string>();

Upvotes: 4

Related Questions