zoukankan      html  css  js  c++  java
  • (转)读取XML数据到treeView中

    参考资料:http://www.cnblogs.com/codingsilence/archive/2011/04/13/2146562.html
    /// <summary>
            ///   绑定xml数据到treeview中区
            /// </summary>
            public void bindXmlToTreeView(XmlNodeList nodeList,TreeNodeCollection treeNode)
            {
           
                foreach (XmlNode node in nodeList)
                {
                    XmlElement xe = (XmlElement)node;
                    TreeNode newTreeNode = new TreeNode();
                    newTreeNode.Text = xe.GetAttribute("name");
                    newTreeNode.Name = xe.GetAttribute("value");
                    treeNode.Add(newTreeNode);
                   
                    if (node.HasChildNodes)
                    {
                        bindXmlToTreeView(node.ChildNodes,newTreeNode.Nodes);
                    }
                }        }
     

    使用:

    复制代码
    XmlDocument xmlDoc = new XmlDocument();//
    XmlNodeList currentXmlNodeList = null;   

    xmlDoc.Load(baseDir);

    currentXmlNodeList = xmlDoc.SelectNodes("/root/GasTree");

    bindXmlToTreeView(currentXmlNodeList,treeView1.Nodes);

  • 相关阅读:
    微信小程序开发入门(六)
    JS计算日期加上指定天数得到新的日期
    Java中substring()
    List集合去除重复数据
    按钮倒计时
    jQuery中each方法
    Math三个函数
    jQuery表单提交
    jQuery 序列化表单数据
    正则取小数点后面几位
  • 原文地址:https://www.cnblogs.com/hhhh2010/p/3614053.html
Copyright © 2011-2022 走看看