The effect is as follows
//Defining Dictionariesdictionary<string,string> Address =Newdictionary<string,string>(); voidLoadData () {//This is the data you want to add//you can also choose to add dynamically, but considering that the data is not much, it does not affect performance.Address.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","Municipalities"); //add to the Capital drop-down box by loop value foreach(stringProvinceinchaddress.values) {//avoid repeated additions to the provincial capital name if(!ComboBoxEdit1.Properties.Items.Contains (province)) ComboBoxEdit1.Properties.Items.Add (province); }//provincial capital drop-down box select Index MethodPrivate voidComboboxedit1_selectedindexchanged (Objectsender, EventArgs e) { //Empty the City drop-down box to avoid appending data before adding//you can also choose to add them dynamicallycomboBoxEdit2.Properties.Items.Clear (); //find key values by value foreach(keyvaluepair<string,string> kvpinchAddress) { if(KVP. Value.equals (ComboBoxEdit1.SelectedItem.ToString ())) {ComboBoxEdit2.Properties.Items.Ad D (KVP. Key); } } }
A simple example realization method of the drop box linkage in province cities