首页  编辑  

TreeView上下级Checked属性关联处理

Tags: /C#/界面处理/ListView_TreeView/   Date Created:

private void TreeNodeChild( TreeNode ATreeNode, bool AChecked) //

{

    if (ATreeNode == null ) return ;

   ATreeNode . Checked = AChecked;

    foreach ( TreeNode vTreeNode in ATreeNode . Nodes)

       TreeNodeChild(vTreeNode, AChecked);

}

private void TreeNodeCheck( TreeNode ATreeNode, bool AChecked)

{

    if (ATreeNode == null ) return ;

   ATreeNode . Checked = AChecked;

    if (AChecked) //

   {

       TreeNodeCheck(ATreeNode . Parent, AChecked);

   }

    else

   {

        if (ATreeNode . Parent != null && ATreeNode . Parent . Checked)

       {

            foreach ( TreeNode vTreeNode in ATreeNode . Parent . Nodes)

                if (vTreeNode . Checked) return ;

           TreeNodeCheck(ATreeNode . Parent, AChecked); //

       }

   }

}

private bool updateTreeNode = false ;

private void treeView1_AfterCheck( object sender , TreeViewEventArgs e)

{

    if (updateTreeNode) return ; //

   updateTreeNode = true ;

    try

   {

       TreeNodeChild(e . Node, e . Node . Checked); //

       TreeNodeCheck(e . Node, e . Node . Checked);

   }

    finally

   {

       updateTreeNode = false ;

   }

}