zoukankan      html  css  js  c++  java
  • 递归算法绑定节点

            #region 绑定节点
            /// <summary>
            /// 绑定TreeView_2009-05-19
            /// </summary>
            /// <param name="data"></param>
            public void Bind() {
                //1.判断数据源和控件是否为空
                //2.把数据递归到树上
                if (DataSource == null||TV == null) return;
                foreach (Category ci in DataSource){
                    if (ci.ParentCategoryID == ROOTCATEGORYID){
                        TreeNode tn = new TreeNode();
                        tn.Text = ci.CategoryName;
                        tn.Name = ci.CategoryId.ToString();
                        tn.Tag = ci.ParentCategoryID;
                        TV.Nodes.Add(tn);
                        BindChildNode(tn);
                    }
                }
            }
            /// <summary>
            /// 绑定子_2009-05-19
            /// </summary>
            /// <param name="tn"></param>
            private void BindChildNode(TreeNode tn) {
                foreach (Category cichild in DataSource){
                    if (cichild.ParentCategoryID.ToString() == tn.Name.ToString()) {
                        TreeNode tnchild = new TreeNode();
                        tnchild.Text = cichild.CategoryName;
                        tnchild.Name = cichild.CategoryId.ToString();  
                        tnchild.Tag = cichild.ParentCategoryID;        
                        BindChildNode(tnchild);
                        tn.Nodes.Add(tnchild);
                    }
                }
            }
            #endregion
  • 相关阅读:
    第四章
    第二章
    第三章
    第一章
    第十章心得
    第九章心得
    第八章心得
    第七章心得
    第六章心得
    第五章心得
  • 原文地址:https://www.cnblogs.com/chinaniit/p/1501315.html
Copyright © 2011-2022 走看看