Export (0) Print
Expand All

TreeNode.Checked Property

Gets or sets a value indicating whether the tree node is in a checked state.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public bool Checked { get; set; }

Property Value

Type: System.Boolean
true if the tree node is in a checked state; otherwise, false.

The following code example highlights any TreeNode objects a TreeView control that has its Checked property set to true by setting its BackColor property to Yellow. This code requires that you have a TreeView control on a Form with a collection of TreeNode objects.

public void HighlightCheckedNodes()
{
   int countIndex = 0;
   string selectedNode = "Selected customer nodes are : ";
   foreach (TreeNode myNode in myTreeView.Nodes[0].Nodes)
   {
      // Check whether the tree node is checked. 
      if(myNode.Checked)
      {
         // Set the node's backColor.
         myNode.BackColor = Color.Yellow;
         selectedNode += myNode.Text+" ";
         countIndex++;
      }
      else
         myNode.BackColor = Color.White;
   }

   if(countIndex > 0)
      MessageBox.Show(selectedNode);
   else
      MessageBox.Show("No nodes are selected");
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft