TreeNode.Checked Property
.NET Framework 4
Gets or sets a value indicating whether the tree node is in a checked state.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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"); }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.