private void TreeView1_AfterCheck(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
// For Select all to sub tree
TreeNode parent_node = e.Node;
bool is_checked = parent_node.Checked;
for (int i = 0; i <= e.Node.Nodes.Count - 1; i++) {
SetSubtreeChecked(parent_node.Nodes(i), is_checked);
}
bool blnUncheck = false;
//---------------------------------------------------
//Check to see if a parent node exists.
if ((e.Node.Parent != null)) {
//Loop through the child nodes.
foreach (TreeNode child in e.Node.Parent.Nodes) {
//Check to see if the current node is unchecked.
if (child.Checked == true) {
//Set the variable.
blnUncheck = true;
}
}
//Check the variable.
if (blnUncheck == false) {
//Check the parent node.
e.Node.Parent.Checked = false;
} else {
//Uncheck the parent node.
e.Node.Parent.Checked = true;
}
}
}
//'========================================================
//' For Tree view Items Validation
//'========================================================
private void SetSubtreeChecked(TreeNode parent_node, bool is_checked)
{
// Set the parent's Checked value.
parent_node.Checked = is_checked;
// Set the child nodes' Checked values.
for (int i = 0; i <= parent_node.Nodes.Count - 1; i++) {
SetSubtreeChecked(parent_node.Nodes(i), is_checked);
}
}
Referenced by: http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/f4269ae8-f788-4637-a454-df0f6bf05db5/