I have a tree view that has some parent nodes and child nodes.I have four buttons. In which two buttons are of checked and unchecked only parent nodes and two buttons are of child nodes.
I want checked only parent nodes if i click btnAllParentChecked
and unchecked if i click btnAllparentUnchecked
and similarly for child nodes.I have done some code for child nodes.
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);
}
How can i implement this functionality in treeview?