树节点—点击事件 — 根据节点名字,递归加载项

#region树节点 —点击事件 — 根据节点名字加载检查项

    /// 
    /// 根据节点名字加载检查项
    /// 
    /// 节点的名字
    /// 检查项成员链表
    public void CheckEmployee(string PersonName, List checkProjects)
    {
    
        _Checks = checkProjects
        TreeNode[] treeNode = treeView.Nodes.Find(PersonName, true);
        for (int i = 0; i < treeNode.Length; i++)
        {
            //在所选节点加载检查项
            LoadChecks(treeNode[i]);
            //展开检查项
            treeNode[i].ExpandAll();
            //让其父节点展开
            IsPrate(treeNode[i]);
        }
        
    }
    /// 
    /// 递归 让其父节点展开
    /// 
    /// 
    public void IsPrate(TreeNode tn)
    {
        if (tn.Parent!=null)
        {
            tn.Parent.Expand();
            IsPrate(tn.Parent);
        }
        
    }
    #endregion

    #region 对选中节点进行检查项的递归加载
    /// 
    /// 一级检查项的递归加载
    /// 
    /// 
    public void LoadChecks(TreeNode tn)
    {
        foreach (CheckProject checkitem in _Checks)
        {
            //一级检查项
            if (!tn.Nodes.ContainsKey(checkitem.CheckProjectName))
            {
                TreeNode tn1 = new TreeNode();
                tn1.Name = checkitem.CheckProjectName;
                tn1.Text = checkitem.CheckProjectName;

                tn.Nodes.Add(tn1);
                SecondLoadChecks(tn1);
            }
        }
    }
    /// 
    /// 二级检查项递归加载
    /// 
    /// 
    public void SecondLoadChecks(TreeNode tn)
    {
        foreach (CheckProject item in _Checks)
        {
            if (item.CheckProjectName == tn.Name)
            {
                TreeNode tn1 = new TreeNode();
                tn1.Text = item.Sub_CheckProject;
                tn1.Name = item.Sub_CheckProject;
                tn.Nodes.Add(tn1);
                SecondLoadChecks(tn1);
            }
        }

    }

#endregion

你可能感兴趣的:(C#)