居委会街道管理系统

    xiaoxiao2021-03-25  131

    居委会街道管理系统,

    xml解析

    此项目所需的类

    将xml解析的文件保存到双列集合中

    public class Jiexi { public Dictionary<string, Raddress> list1 = new Dictionary<string, Raddress>(); //public List<Raddress> list1=new List<Raddress>(); public void ReadXML() { XmlDocument doc = new XmlDocument(); doc.Load("Address.xml"); XmlNode root = doc.DocumentElement; string value = root.Attributes["name"].Value; foreach (XmlNode item in root.ChildNodes) { //创建一个地址对象 string juweihui= item.Attributes["name"].InnerText; //address.Fjname = root.Attributes["smid"].InnerText; foreach (XmlNode child in item.ChildNodes) { string num = child.Attributes["name"].InnerText; foreach (XmlNode node in child.ChildNodes) { Address ad = new Address(); ad.Juwei = juweihui; ad.Street = value; ad.Louhao = num; Raddress raddress = new Raddress(); raddress.Num = node.InnerText; raddress.Address = ad; list1.Add(ad.Juwei+ad.Louhao+raddress.Num,raddress); } } } }

    将解析完的绑定到TreeView上(*****************************重点**************************)

    private void FrmShow_Load(object sender, EventArgs e) { jiesx.ReadXML(); TreeNode root = null; TreeNode node2 = null; TreeNode node1 = null; TreeNode node3 = null; int num = 1; string str1 = ""; string str2 = ""; string str3 = ""; foreach (Raddress address in jiesx.list1.Values) { if (num==1) { root = new TreeNode("石牌街道"); tvList.Nodes.Add(root); } num = 2; if (str1 != address.Address.Juwei) { node2 = new TreeNode(address.Address.Juwei); root.Nodes.Add(node2); } str1 = address.Address.Juwei; if (str2 != address.Address.Louhao) { node1 = new TreeNode(address.Address.Louhao); node2.Nodes.Add(node1); } str2 = address.Address.Louhao; //MessageBox.Show(address.Address.Louhao); if (str3 != address.Num) { node3 = new TreeNode(address.Num); node1.Nodes.Add(node3); } str3 = address.Num; } }

    最后将TextBox控件的内容绑定

    private void tvList_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode tree = tvList.SelectedNode; if (tree!=null&&tree.Level==3) { string text = tree.Parent.Parent.Text+tree.Parent.Text+tree.Text; //MessageBox.Show(text); txtjuweihui.Text = jiesx.list1[text].Address.Juwei; txtStreet.Text = jiesx.list1[text].Address.Street; txtSum.Text = jiesx.list1[text].Num; txtNum.Text = jiesx.list1[text].Address.Louhao; } }

    转载请注明原文地址: https://ju.6miu.com/read-38987.html

    最新回复(0)