Checkboxes in TreeView control in C#

 
A check box can display to the left of both the tree node label and tree node Image, if any. Check boxes allow the user to select more than one tree node at a time.You can do it with the help of ‘CheckBoxes’ property.

You can find CheckBoxes is true if a check box is displayed next to each tree node in the tree view control otherwise, false. The default value of CheckBoxes is false.
This causes all tree nodes to be collapsed, with the exception of the selected TreeNode.
Following are the some code snippets foe handling checkboxes in treeview:

Set the Checkboxes to Treeview at run time

TreeView1.CheckBoxes = true;

Set the checked state of one of the nodes to True

treeView1.Nodes[0].Nodes[1].Checked = true;

How to check that the specified TreeNode has checked child nodes.

private bool _HasCheckedChildNodes(TreeNode _node)
  {
    if (_node.Nodes.Count == 0) return false;
    foreach (TreeNode _childNode in _node.Nodes)
     {
        if (_childNode.Checked) return true;
        if (_HasCheckedChildNodes(_childNode)) return true;
      }
       return false;
   }

Determine that checkbox on a treenode has been checked or unchecked

private void TreeView1_AfterCheck(object sender, TreeViewEventArgs e)
        {
            TreeNode _node = e.Node;
            MessageBox.Show("text of node is " + e.Node.Text);
            if (e.Node.Checked == true)
            {
                MessageBox.Show("checked");
            }
            else
            {
                MessageBox.Show("Unchecked");
            }
        }