Implementation of provincial/municipal drop-down lists linking simple instances, and provincial drop-down lists

Source: Internet
Author: User

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 );}}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.