-
March 21st, 2012, 10:30 AM
#1
filling a combobox with countries
I need to fill a combobox with countries.
For this I have the following code:
// fill country combobox with countries
public List<string> GetCountryList()
{
List<string> cultureList = new List<string>();
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
cultureList.Add("-- Select Country --");
foreach(CultureInfo culture in cultures)
{
// check if it's not a invariant culture
if(culture.LCID != 127)
{
RegionInfo region = new RegionInfo(culture.LCID);
// add countries that are not in the list
if(!(cultureList.Contains(region.EnglishName)))
{
cultureList.Add(region.EnglishName);
}
}
}
cultureList.Sort(); // sort alphabetically
return cultureList;
}
Code I found about this on the internet was all a couple years old and made for windows XP, in 7 you get some extra data. so i found the extra check - if(culture.LCID != 127)
however now it won't compile on
RegionInfo region = new RegionInfo(culture.LCID);
giving
ArgumentException was unhandled
Culture ID 1 (0x0001) is a neutral culture; a region cannot be created from it.
Parameter name: culture
and to be exact this is the 2nd neutral culture it comes across. So why does it get the 1st, and not the 2nd?
but most important how can I solve this?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|