首页 > 代码库 > 如何动态添加树节点(.NET)

如何动态添加树节点(.NET)

很简单:

就两方法:

 //添加父节点
    public void AddNode()
    {
        KunSoftLogic.WIM.WIM10100 logic_WIM10100 = new KunSoftLogic.WIM.WIM10100();
        DataTable dt = new DataTable();
        dt = logic_WIM10100.AddPNode().Tables[0];
        Node node = new Node();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            node = new Node();
            node.Text = dt.Rows[i]["Docdate"].ToString();
            node.Tag = dt.Rows[i]["Docdate"].ToString();
            AddSubNode(node);
            UltraWebTree1.Nodes.Add(node);
        }
    }
        //添加子节点
        
        public void AddSubNode(Node node)
        {
            KunSoftLogic.WIM.WIM10100 logic_WIM10100 = new KunSoftLogic.WIM.WIM10100();
            DataTable dt = new DataTable();
            dt = logic_WIM10100.AddSecNode(node.Tag.ToString());
            Node secnode = new Node();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                secnode = new Node();
                secnode.Text = dt.Rows[i]["DocId"].ToString();
                secnode.Tag = node.Text;
                node.Nodes.Add(secnode);
            }

        }

 

假如树有三层时,同上方法,再写一函数 添加第二层的子节点。

如何动态添加树节点(.NET)