// update check status for parent and child privatevoidUpdateCheckStatus(TreeViewEventArgs e) { CheckAllChildNodes(e.Node); UpdateAllParentNodes(e.Node); }
elseif (!parent.Checked && treeNode.Checked) { bool all = true; foreach (TreeNode node in parent.Nodes) { if (!node.Checked) { all = false; break; } } if (all) { parent.Checked = true; UpdateAllParentNodes(parent); } } } }
// updates all child tree nodes recursively. privatevoidCheckAllChildNodes(TreeNode treeNode) { foreach (TreeNode node in treeNode.Nodes) { node.Checked = treeNode.Checked; if (node.Nodes.Count > 0) { // If the current node has child nodes, call the CheckAllChildsNodes method recursively. this.CheckAllChildNodes(node); } } }