码迷,mamicode.com
首页 > Windows程序 > 详细

Winfrom TreeView 无限分级

时间:2016-03-10 12:40:41      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:

 public void AddTreeView(string ParentID, TreeNode pNode, DataSet set)
        {
            string strName = "N_Name";                  // 数据库名字字段
            string strID = "U_ID";                           // 数据库ID字段
            string strParentID = "N_PaterId";           // 数据库父级ID字段
            DataTable dt = set.Tables[0];
            DataView dvTree = new DataView(dt);   //添加数据源
            dvTree.RowFilter = "N_PaterId = ‘" + ParentID + "‘";  //过滤节点条件
            foreach (DataRowView Row in dvTree)
            {
                TreeNode Node = new TreeNode();
                if (pNode == null)
                {
                    Node.Text = Row[strName].ToString();
                    Node.Name = Row[strName].ToString();
                    Node.Tag = Row[strID].ToString();
                    Node.ImageIndex = 1;
                    this.treeView1.Nodes.Add(Node);
                    AddTree(Row[strID].ToString(), Node, set); //再次递归
                }
                else
                {
                    Node.Text = Row[strName].ToString();
                    Node.Name = Row[strName].ToString();
                    Node.Tag = Row[strID].ToString();
                    Node.ImageIndex = 1;
                    pNode.Nodes.Add(Node);
                    AddTree(Row[strID].ToString(), Node, set); //再次递归
                }
            }
        }

Winfrom TreeView 无限分级

标签:

原文地址:http://www.cnblogs.com/jobyym/p/5261346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!