Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
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 */
public boolean get_Checked ()

/** @property */
public void set_Checked (boolean value)

public function get Checked () : boolean

public function set Checked (value : boolean)

Property Value

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");
}

public void HighlightCheckedNodes()
{
    int countIndex = 0;
    String selectedNode = "Selected customer nodes are : ";
    for (int iCtr = 0; iCtr < myTreeView.get_Nodes().get_Item(0).
        get_Nodes().get_Count(); iCtr++) {
        TreeNode myNode = myTreeView.get_Nodes().get_Item(0).
            get_Nodes().get_Item(iCtr);
        // Check whether the tree node is checked.
        if (myNode.get_Checked()) {
            // Set the node's backColor.
            myNode.set_BackColor(Color.get_Yellow());
            selectedNode += myNode.get_Text() + " ";
            countIndex++;
        }
        else {
            myNode.set_BackColor(Color.get_White());
        }
    }
    if (countIndex > 0) {
        MessageBox.Show(selectedNode); 
    }
    else {
        MessageBox.Show("No nodes are selected");
    }
} //HighlightCheckedNodes

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft