C # XML Provincial linkage

Source: Internet
Author: User

Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;using system.xml;using System.IO;namespace windowsformsapplication1{public partial class Form1:form {public Form1 () {Initializeco        Mponent ();        } list<string> Sheng = new list<string> ();        list<string> shi = new list<string> ();        list<string> qua = new list<string> ();            private void Form1_Load (object sender, EventArgs e) {XmlDocument doc = new XmlDocument (); Doc.            Load ("Provinces.xml");            ComboBox1.Items.Clear (); Sheng.            Clear (); XmlNodeList nodelist = doc.                     SelectNodes ("/provinces/province"); foreach (XmlNode item in nodelist) {COMBOBOX1.ITEMS.ADD (item. attributes["Provincename"].                Value); Sheng. ADD (item.attributes["ID"].                            Value);                   } combobox1.selectedindex = 0; private void ComboBox1_SelectedIndexChanged (object sender, EventArgs e) {XmlDocument XM = new            XmlDocument (); Xm.            Load ("Cities.xml"); Shi.            Clear ();            ComboBox2.Items.Clear ();            String cid = Sheng[combobox1.selectedindex]; XmlNodeList Citys = xm.                        SelectNodes ("/cities/city[@PID =" +cid+ "]"); foreach (XmlNode item in citys) {COMBOBOX2.ITEMS.ADD (item. attributes["CityName"].                    Value); Shi. ADD (item. attributes["ID"].                            Value);        } combobox2.selectedindex = 0; private void Combobox3_selectedindexchanged (object sender, EventArgs e) {} Priva te void Combobox2_selectedindexchanged (object sender, EventArgs e) {XmlDocument qu = new XMLDOcument (); Qu.            Load ("Districts.xml"); Qua.            Clear ();            ComboBox3.Items.Clear ();            String qid = shi[combobox2.selectedindex]; XmlNodeList Qux = qu.            SelectNodes ("/districts/district[@CID =" + qid + "]"); foreach (XmlNode item in Qux) {COMBOBOX3.ITEMS.ADD (item. attributes["Districtname"].                Value); Qua. ADD (item. attributes["ID"].            Value);        } combobox3.selectedindex = 0; }    }}

  

C # XML Provincial linkage

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.