Freigeben über


TreeNode.Checked Eigenschaft

Definition

Ruft einen Wert ab, der angibt, ob der Strukturknoten aktiviert ist, oder legt diesen fest.

public:
 property bool Checked { bool get(); void set(bool value); };
public bool Checked { get; set; }
member this.Checked : bool with get, set
Public Property Checked As Boolean

Eigenschaftswert

true, wenn der Strukturknoten aktiviert ist, andernfalls false.

Beispiele

Im folgenden Codebeispiel werden alle TreeNode Objekte eines TreeView Steuerelements hervorgehoben, dessen Checked -Eigenschaft auf true festgelegt ist, indem die BackColor -Eigenschaft auf Yellowfestgelegt wird. Dieser Code erfordert, dass Sie über ein TreeView -Steuerelement Form mit einer Auflistung von TreeNode -Objekten verfügen.

public:
   void HighlightCheckedNodes()
   {
      int countIndex = 0;
      String^ selectedNode = "Selected customer nodes are : ";
      IEnumerator^ myEnum = myTreeView->Nodes[ 0 ]->Nodes->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         TreeNode^ myNode = safe_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, " " );
            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 : ";
   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 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

Gilt für:

Weitere Informationen