Hey all I am currently practicing my error handling processes and am having trouble filling up a combobox with a list of all the countries so that the user can choose what country they are located in. What I am creating is something like a registration form. I found an algorithm in the internet about filling up the combobox, but I do not understand it and it does not work properly in windows 7, it gets a There is no region associated with the invariant culture sort of error and does not run properly, it compiles but does not run. Here is the algorithm:
private void RegisterUser_Load(object sender, EventArgs e)
{
comBoxCountry.Items.Insert(0, "-- Select Country --");
comBoxCountry.SelectedIndex = 0;
comBoxEmployeeNum.Items.Insert(0, "-- Select Number of Employees --");
comBoxEmployeeNum.SelectedIndex = 0;
comBoxReqType.Items.Insert(0, "-- Select Request Type --");
comBoxReqType.SelectedIndex = 0;
foreach (string country in getCountryList())
{
comBoxCountry.Items.Add(country);
}
for (int i = 1; i < 51; i++)
{
comBoxEmployeeNum.Items.Add(Convert.ToString(i));
}
for (int i = 1; i < 11; i++)
{
comBoxReqType.Items.Add("Request " + Convert.ToString(i));
}
}
public static List<string> getCountryList()
{
List<string> cultureList = new List<string>();
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
foreach (CultureInfo culture in cultures)
{
RegionInfo region = new RegionInfo(culture.LCID);
//RegionInfo region = new RegionInfo(culture.LCID);
if (!(cultureList.Contains(region.EnglishName)))
{
cultureList.Add(region.EnglishName);
}
}
return cultureList;
}
It gets the error at this line specifically:
RegionInfo region = new RegionInfo(culture.LCID);
I tried running this algorithm in windows xp and it works flawlessly. I don't know what's wrong here. I also do not understand the algorithm :( If anyone could show or give hints on how I can create something similar I would be very grateful!
Oh and what is the difference between keypress and keydown? as I understand keypress is a combination of keydown and keyup, but that's only thing I understand about it. I am thinking of using it in my error handling processes.
Thanks :D