博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

treeview 的深层添加节点

Posted on 2008-09-17 19:26  hyd309  阅读(392)  评论(0编辑  收藏  举报

   private void SetTree()       //设置treeview 数据绑定
    {
        TreeView.Nodes.Clear();
        BM1.IBLL.IFileRgstBLL bll = BM1.Factory.BLLFactory.CreateIFileRgstBLL();
        ArrayList list = bll.GetPath(Session["CMP_ID"].ToString(), false,Session["LANGUAGE"].ToString(), 0);

        TreeNode Parent = new TreeNode("文档管理","Root");

        for (int i = 0; i < list.Count; i++ )
        {
            FileRgstVO vo = (FileRgstVO)list[i];
            if (vo.GetParent_Num == 0)
            {
                Parent.ChildNodes.Add(new TreeNode(vo.GetPath_Name, vo.GetPath_Num.ToString()));
                continue;
            }
            //Parent = aa(vo, Parent);
            //递归调用添加子节点
            aa(vo, Parent);
        }
        TreeView.Nodes.Add(Parent);
    }

    private bool aa(FileRgstVO vo , TreeNode treeNode)  //遍历添加子节点
    {
        if (vo.GetParent_Num.ToString() == treeNode.Value)
        {
            treeNode.ChildNodes.Add(new TreeNode(vo.GetPath_Name, vo.GetPath_Num.ToString()));
            return true;
        }
        bool flg = false;

        foreach (object obj in treeNode.ChildNodes)
        {
            TreeNode tree = (TreeNode)obj;
            if (vo.GetParent_Num.ToString() == tree.Value)
            {
                tree.ChildNodes.Add(new TreeNode(vo.GetPath_Name, vo.GetPath_Num.ToString()));
                flg = true;
                break;
            }
            else
            {
                flg = aa(vo, tree);
                if (flg)
                    break;
            }
        }
        return flg;
    }