Implementation of provincial/municipal drop-down lists linking simple instances, and provincial drop-down lists
The effect is as follows:
// Define the Dictionary <string, string> Address = new Dictionary <string, string> (); void loadData () {// This is the data you want to add. // you can also choose to dynamically Add the data, but the Address is implemented because the data is not much and does not affect the performance. add ("Mianyang", "Sichuan"); Address. add ("Chengdu", "Sichuan"); Address. add ("Guanghan", "Sichuan"); Address. add ("Nanjing", "Jiangsu"); Address. add ("Yangzhou", "Jiangsu"); Address. add ("Wuxi", "Jiangsu"); Address. add ("Zhuhai", "Guangzhou"); Address. add ("Dongguan", "Guangzhou"); Address. add ("Shenzhen", "Guangzhou"); Address. add ("Shanghai", "municipality"); // Add the data to the provincial capital using the cyclic Value Drop-down box foreach (string province in Address. Values) {// judge to avoid repeated provincial capitals if (! ComboBoxEdit1.Properties. items. contains (province) comboBoxEdit1.Properties. items. add (province);} // select the index method private void comboBoxEdit1_SelectedIndexChanged (object sender, EventArgs e) from the provincial capital drop-down box) {// clear the municipal drop-down box to avoid appending data before adding it. // you can also choose to dynamically add comboBoxEdit2.Properties. items. clear (); // query the key value foreach (KeyValuePair <string, string> kvp in Address) {if (kvp. value. equals (comboBoxEdit1.SelectedItem. toString () {comboBoxEdit2.Properties. items. add (kvp. key );}}}