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 ;
}
}