• 街道管理系统


    执行后

    窗体加载时,填充TreeView,点击某一层级时,将文本填充到右侧的textBox文本框中

    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 Street
    {
        public partial class FrmMain : Form
        {
            public FrmMain()
            {
                InitializeComponent();
            }
    
            private void FrmMain_Load(object sender, EventArgs e)
            {
                XmlDocument xml = new XmlDocument();
                xml.Load("Address.xml");
                XmlElement root = xml.DocumentElement;
                TreeNode tn = new TreeNode();
                tn.Text = root.Attributes["name"].InnerText;
                tvStreet.Nodes.Add(tn);
                TreeNode no = null;
                TreeNode chids = null;
                foreach (XmlNode item in root.ChildNodes)
                {
                    no = new TreeNode(item.Attributes["name"].Value);
                    tn.Nodes.Add(no);
                    TreeNode chid = null;
                    foreach (XmlNode node in item.ChildNodes)
                    {
                        chid = new TreeNode(node.Attributes["name"].Value);
                        no.Nodes.Add(chid);
                        foreach (XmlNode items in node.ChildNodes)
                        {
                            chids = new TreeNode(items.InnerXml);
                            chid.Nodes.Add(chids);
    
                        }
                    }
                }
            }
    
            private void tvStreet_AfterSelect(object sender, TreeViewEventArgs e)
            {
                if (this.tvStreet.SelectedNode.Level == 0)
                {
                    textBox1.Text = tvStreet.SelectedNode.Text;
                }
                else if (this.tvStreet.SelectedNode.Level == 1)
                {
                    textBox1.Text = tvStreet.SelectedNode.Parent.Text;
                    textBox2.Text = tvStreet.SelectedNode.Text;
                }
                else if (this.tvStreet.SelectedNode.Level == 2)
                {
                    textBox1.Text = tvStreet.SelectedNode.Parent.Parent.Text;
                    textBox2.Text = tvStreet.SelectedNode.Parent.Text;
                    textBox3.Text = tvStreet.SelectedNode.Text;
                }
                else if (this.tvStreet.SelectedNode.Level == 3)
                {
                    textBox1.Text = tvStreet.SelectedNode.Parent.Parent.Parent.Text;
                    textBox2.Text = tvStreet.SelectedNode.Parent.Parent.Text;
                    textBox3.Text = tvStreet.SelectedNode.Parent.Text;
                    textBox4.Text = tvStreet.SelectedNode.Text;
                }
            }
        }
    }
  • 相关阅读:
    asp.net的decimal保留两位小数
    由于管理员设置的策略,该磁盘处于脱机状态-Win 2008 R2
    论大公司的通病和缺点
    sql server删除数据后空间无变化处理方法
    sql server压缩数据库和日志文件
    SQL千万级数据设计和优化
    SQL Server索引怎么用
    在电脑上测试手机网站
    asp.net实现GZip压缩和GZip解压
    WebService教程和分析
  • 原文地址:https://www.cnblogs.com/fl72/p/8360390.html
Copyright © 2020-2023  润新知