本文介绍了获取所选国家/地区的状态列表。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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.

推荐答案


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.


这篇关于获取所选国家/地区的状态列表。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:06