我有一个包含一些父节点和子节点的树视图。我有四个按钮。其中两个按钮是选中和未选中的只有父节点,两个按钮是子节点。如果我单击,我只想检查父节点,如果我单击btnAllParentChecked
,我只想取消选中btnAllparentUnchecked
子节点。我已经为子节点做了一些代码。
Boolean bChildTrigger = true;
Boolean bParentTrigger = true;
private void CheckAllChildren(TreeNodeCollection trNodeCollection, Boolean bCheck)
{
bParentTrigger = false;
foreach (TreeNode ctn in trNodeCollection)
{
bChildTrigger = false;
ctn.Checked = bCheck;
bChildTrigger = true;
CheckAllChildren(ctn.Nodes, bCheck);
}
bParentTrigger = true;
}
private void btnAllPropertyChecked_Click(object sender, EventArgs e)
{
CheckAllChildren(treSelector.Nodes, true);
}
private void btnAllPropertyUnChecked_Click(object sender, EventArgs e)
{
CheckAllChildren(treSelector.Nodes, false);
}
如何在树视图中实现此功能?