/// TreeView checked事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tvMenu_AfterCheck(object sender, TreeViewEventArgs e)
{
CheckAll(e.Node);
}
/// <summary>
/// 全部节点check处理
/// </summary>
/// <param name="eTreeNode"></param>
private void CheckAll(TreeNode eTreeNode)
{
tvMenu.AfterCheck -=new TreeViewEventHandler(tvMenu_AfterCheck);
if (eTreeNode.Parent != null)
{
CheckParent(eTreeNode);
}
if (eTreeNode.Nodes.Count > 0)
{
foreach (TreeNode mTN in eTreeNode.Nodes)
{
mTN.Checked = eTreeNode.Checked;
foreach (TreeNode mTNSub in mTN.Nodes)
{
mTNSub.Checked = mTN.Checked;
CheckSub(mTNSub);
}
}
}
tvMenu.AfterCheck += new TreeViewEventHandler(tvMenu_AfterCheck);
}
/// <summary>
/// 父节点处理
/// </summary>
/// <param name="eTreeNode"></param>
private void CheckParent(TreeNode eTreeNode)
{
if (eTreeNode.Parent == null)
{
return;
}
eTreeNode.Parent.Checked = eTreeNode.Checked;
foreach (TreeNode mTN in eTreeNode.Parent.Nodes)
{
eTreeNode.Parent.Checked = (eTreeNode.Parent.Checked || mTN.Checked);
if (mTN.Parent != null)
{
CheckParent(mTN.Parent);
}
}
}
/// <summary>
/// 子节点处理
/// </summary>
/// <param name="eTreeNode"></param>
private void CheckSub(TreeNode eTreeNode)
{
foreach (TreeNode mTN in eTreeNode.Nodes)
{
mTN.Checked = eTreeNode.Checked;
CheckSub(mTN);
}
}