TreeNode.Checked Property
Gets or sets a value indicating whether the tree node is in a checked state.
[Visual Basic] Public Property Checked As Boolean [C#] public bool Checked {get; set;} [C++] public: __property bool get_Checked(); public: __property void set_Checked(bool); [JScript] public function get Checked() : Boolean; public function set Checked(Boolean);
Property Value
true if the tree node is in a checked state; otherwise, false.
Example
[Visual Basic, C#, C++] The following 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 assumes you have a TreeView control on a Form with a collection of TreeNode objects.
[Visual Basic] Public Sub HighlightCheckedNodes() Dim countIndex As Integer = 0 Dim selectedNode As String = "Selected customer nodes are : " Dim myNode As TreeNode For Each myNode In myTreeView.Nodes(0).Nodes ' Check whether the tree node is checked. If myNode.Checked Then ' Set the node's backColor. myNode.BackColor = Color.Yellow selectedNode += myNode.Text + " " countIndex += 1 Else myNode.BackColor = Color.White End If Next myNode If countIndex > 0 Then MessageBox.Show(selectedNode) Else MessageBox.Show("No nodes are selected") End If End Sub [C#] 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"); } [C++] public: void HighlightCheckedNodes() { int countIndex = 0; String* selectedNode = S"Selected customer nodes are : "; IEnumerator* myEnum = myTreeView->Nodes->Item[0]->Nodes->GetEnumerator(); while (myEnum->MoveNext()) { TreeNode* myNode = __try_cast<TreeNode*>(myEnum->Current); // Check whether the tree node is checked. if (myNode->Checked) { // Set the node's backColor. myNode->BackColor = Color::Yellow; selectedNode = String::Concat(selectedNode, myNode->Text, S" "); countIndex++; } else myNode->BackColor = Color::White; } if (countIndex > 0) MessageBox::Show(selectedNode); else MessageBox::Show(S"No nodes are selected"); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
See Also
TreeNode Class | TreeNode Members | System.Windows.Forms Namespace | CheckBoxes