zoukankan      html  css  js  c++  java
  • c# XML省市联动

    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()
            {
                InitializeComponent();
            }
            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)
            {
               
    
            }
    
            private 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;
            }
        }
    }
    

      

  • 相关阅读:
    for循环中创建线程执行问题
    MySQL学习总结之路(第六章:表类型【存储引擎】的选择)
    Tensorflow的下载和安装
    C# 和 Python 的 hash_md5加密方法
    MySQL学习总结之路(第五章:函数)
    MySQL学习总结之路(第四章:运算符)
    MySQL学习总结之路(第三章:数据类型)
    MySQL学习总结之路(第二章:表)
    MySQL学习总结之路(服务与数据库管理)
    CSS居中的方式15种(水平垂直)
  • 原文地址:https://www.cnblogs.com/mengluo/p/5511015.html
Copyright © 2011-2022 走看看