新街道管理

    xiaoxiao2021-03-25  79

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; namespace 街道项目 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Bust bb = new Bust(); private void treeView1_MouseClick(object sender, MouseEventArgs e) { } private void Form1_Load(object sender, EventArgs e) { XmlDocument xml = new XmlDocument(); //读取XML文件 xml.Load("Address.xml"); //读取XML的根节点 XmlNode root = xml.DocumentElement; //将值赋给jiedao bb.jiedao = root.Attributes["name"].Value; //创建根节点 rootNode TreeNode rootNode = new TreeNode(); //为根节点rootNode赋值 rootNode.Text = bb.jiedao; //将根节点rootNode绑定到tvLise控件上 treeView1.Nodes.Add(rootNode); //遍历街道中所有居委会 foreach (XmlNode item in root.ChildNodes) { //创建节点 TreeNode oneNode = new TreeNode(); //赋值 oneNode.Text = item.Attributes["name"].Value; //遍历居委会中所有住房 foreach (XmlNode child in item.ChildNodes) { //创建节点 TreeNode twoNode = new TreeNode(); ///赋值 twoNode.Text = child.Attributes["name"].Value; //遍历住房中所有房间号 foreach (XmlNode node in child.ChildNodes) { //创建节点 TreeNode threeNode = new TreeNode(); //赋值 threeNode.Text = node.InnerText; //将threeNode子节点归属到twoNode父节点 twoNode.Nodes.Add(threeNode); } //将twoNode子节点归属到oneNode父节点 oneNode.Nodes.Add(twoNode); } //将oneNode子节点归属到rootNode根节点 rootNode.Nodes.Add(oneNode); } } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { //为控件txtjiedao 赋值 jiedao.Text = "石牌街道"; //点击节点获取值 TreeNode node = this.treeView1.SelectedNode; if (node.Level == 1) { //赋值 juweuhui.Text = node.Text; } else if (node.Level == 2) { louhao.Text = node.Text; juweuhui.Text = node.Parent.Text; } else if (node.Level == 3) { fangjianhao.Text = node.Text; louhao.Text = node.Parent.Text; juweuhui.Text = node.Parent.Parent.Text; } } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 街道项目 { public class Bust { public string jiedao { get; set; }//街道 public string Juwei { get; set; }//居委会 public string Jianzhu { get; set; }//楼房 public string Room { get; set; } //房间号 } } XML文件 <?xml version="1.0" encoding="utf-8" ?> <root name="石牌街道"> <juwei name="瑞华居委"> <jianzhu smid="6" name="瑞华花园1栋"> <fjname>101室</fjname> <fjname>102室</fjname> </jianzhu> <jianzhu smid="7" name="瑞华花园2栋"> <fjname>101室</fjname> <fjname>102室</fjname> </jianzhu> </juwei> <juwei name="金帝居委"> <jianzhu smid="4" name="金帝花园1栋"> <fjname>101室</fjname> <fjname>102室</fjname> </jianzhu> </juwei> <juwei name="朝阳居委"> <jianzhu smid="5" name="朝阳花园1栋"> <fjname>101室</fjname> <fjname>102室</fjname> </jianzhu> </juwei> </root>
    转载请注明原文地址: https://ju.6miu.com/read-34749.html

    最新回复(0)