获取所选国家/地区的状态列表。

问题描述:

我有两个组合框用于国家/地区,第二个用于状态,第二个应根据国家组合框中选择的值加载。我按照以下方式填写国家组合框:



I have two combo boxes one for country and the second is for states the second one should load based on the value selected in the country combobox. I am populating the country combobox in following way:

private void PopulateCountryComboBox()
{
     RegionInfo country = new RegionInfo(new CultureInfo("en-US", false).LCID);
     List<string> countryNames = new List<string>();
     foreach (CultureInfo cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
     {
          country = new RegionInfo(new CultureInfo(cul.Name, false).LCID);
          countryNames.Add(country.DisplayName.ToString() );
     }
     IEnumerable<string> nameAdded = countryNames.OrderBy(names => names).Distinct();
     foreach (string item in nameAdded)  {CountryComboBox.Items.Add(item);}
}





我如何绑定状态列表国家组合框的选定指数变化?

任何积极的回应都将受到赞赏。



How can I bind the states list on the selected index change of country combobox?
Any positive responses will be appreciated.

我发现这个资源地理数据库转储 [ ^ ]通过giyf搜索。 .Net中没有内置任何可以提供此信息的内容。文化信息并非详尽无遗,绝对不会包括州和县的解决方案。



PS - 我确实在该网站上看到了美国和英国的县dbs - 不知道它是否有效:S
I found this resource Geographing Database dump[^] through a giyf search. There is nothing built in to .Net that can provide this info. Culture info is not anywhere near exhaustive and definitely won't include such resolution as states and counties.

PS - I did see US and UK county dbs on that site - no idea if it works tho :S


你可以处理 SelectedIndexChanged [ ^ ]事件和处理程序内部,您可以更改第二个ComboBox的值,如下所示,



You can handle the SelectedIndexChanged[^] event and inside the handler, you can change the value of the second ComboBox, like this,

void comboBox_SelectedIndexChanged(object sender, EventArgs e) {
   // Handle the event here...
   // Sender = your ComboBox; cast it to ComboBox
   // Get the SelectedIndex and see which country is selected
   // Find the states for that country... And populate the second control
}





这样,您可以在第一个组合框中处理更改,并根据SelectedIndex的值,您可以搜索该国家/地区的州,并将其写入第二个组合框。



This way, you can handle the change in first combo box, and depending on the value of SelectedIndex you can then search for the states for that country, and write them in the second combo box.