c# XML省市联动
2016-05-20 09:41
441 查看
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; } } }
相关文章推荐
- (整理)C#基础知识_泛型的实现
- C# DataGridViewButtonColumn的使用—动态改变按钮的文本
- C#开发中IrisSkin2.dll如图添加到工具箱
- C#重绘DataGridView行
- c#入门第一章
- C# Sort排序
- halcon与C#混合编程
- C# j基本操作-拷贝文件夹的所有内容到另一个文件夹内: 复制代码 1 public static void CopyDir(string srcPath, string实现文件夹的复制以及删除
- C#中的String类型转换
- C#Socket通信
- C# Interface
- C#基础-文件夹复制与删除
- C# 使用FileSystemWatcher来监视文件系统的变化
- C#基础-压缩文件及故障排除
- C#格式化文件大小
- 堆栈和托管堆 c#(2)
- C#Winform程序如何发布并自动升级(图解)
- 【C#】安装windows服务
- C#操作session的类实例
- CLR Via C# 第四章 类型基础——读书笔记