TreeNode.Text Eigenschaft

Definition

Ruft den in der Bezeichnung des Strukturknotens angezeigten Text ab oder legt diesen fest.Gets or sets the text displayed in the label of the tree node.

public:
 property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public string Text { get; set; }
member this.Text : string with get, set
Public Property Text As String

Eigenschaftswert

Der in der Beschriftung des Strukturknotens angezeigte Text.The text displayed in the label of the tree node.

Beispiele

Im folgenden Codebeispiel wird ein Stamm Struktur Knoten erstellt, dem untergeordnete Struktur Knoten zugewiesen werden.The following code example creates a root tree node to assign child tree nodes to. Ein untergeordneter Struktur Knoten für jedes Customer Objekt in einer ArrayList wird dem Stamm Struktur Knoten sowie einem untergeordneten Struktur Knoten für jedes Order Objekt hinzugefügt, das dem Customer Objekt zugewiesen ist.A child tree node for each Customer object in an ArrayList is added to the root tree node as well as a child tree node for each Order object assigned to the Customer object. Das Customer-Objekt wird der Tag-Eigenschaft zugewiesen, und die Struktur Knoten, die Customer Objekte darstellen, werden mit Orange Text angezeigt.The Customer object is assigned to the Tag property, and the tree nodes representing Customer objects are displayed with Orange text. Für dieses Beispiel ist es erforderlich, dass Sie ein Customer und Order-Objekt definiert haben, ein TreeView-Steuerelement auf einem Formund eine ArrayList mit dem Namen customerArray, die Customer-Objekte enthält.This example requires that you have a Customer and Order object defined, a TreeView control on a Form, and an ArrayList named customerArray that contains Customer objects.

ref class Customer
{
public:
   ArrayList^ CustomerOrders;
   String^ CustomerName;
   Customer( String^ myName )
   {
      CustomerName = myName;
      CustomerOrders = gcnew ArrayList;
   }

};

ref class Order
{
public:
   String^ OrderID;
   Order( String^ myOrderID )
   {
      this->OrderID = myOrderID;
   }

};


   void AddRootNodes()
   {
      
      // Add a root node to assign the customer nodes to.
      TreeNode^ rootNode = gcnew TreeNode;
      rootNode->Text = "CustomerList";
      
      // Add a main root treenode.
      myTreeView->Nodes->Add( rootNode );
      
      // Add a root treenode for each 'Customer' object in the ArrayList.
      IEnumerator^ myEnum = customerArray->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Customer^ myCustomer = safe_cast<Customer^>(myEnum->Current);
         
         // Add a child treenode for each Order object.
         int i = 0;
         array<TreeNode^>^myTreeNodeArray = gcnew array<TreeNode^>(5);
         IEnumerator^ myEnum = myCustomer->CustomerOrders->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            Order^ myOrder = safe_cast<Order^>(myEnum->Current);
            myTreeNodeArray[ i ] = gcnew TreeNode( myOrder->OrderID );
            i++;
         }
         TreeNode^ customerNode = gcnew TreeNode( myCustomer->CustomerName,myTreeNodeArray );
         
         // Display the customer names with and Orange font.
         customerNode->ForeColor = Color::Orange;
         
         // Store the Customer Object* in the Tag property of the TreeNode.
         customerNode->Tag = myCustomer;
         myTreeView->Nodes[ 0 ]->Nodes->Add( customerNode );
      }
   }
public class Customer
{
   public ArrayList CustomerOrders;
   public string CustomerName;
   public Customer(string myName)
   {
      CustomerName = myName;
      CustomerOrders = new ArrayList(); 
   }
}
public class Order
{
   public string OrderID;
   public Order(string myOrderID )
   {
      this.OrderID = myOrderID;
   }
}

public void AddRootNodes()
{
   // Add a root node to assign the customer nodes to.
   TreeNode rootNode = new TreeNode();
   rootNode.Text = "CustomerList";
   // Add a main root treenode.
   myTreeView.Nodes.Add(rootNode);

   // Add a root treenode for each 'Customer' object in the ArrayList.
   foreach(Customer myCustomer in customerArray)
   {
      // Add a child treenode for each Order object.
      int i = 0;
      TreeNode[] myTreeNodeArray = new TreeNode[5];
      foreach(Order myOrder in myCustomer.CustomerOrders)
      {
         myTreeNodeArray[i] = new TreeNode(myOrder.OrderID);
         i++;
      }
      TreeNode customerNode = new TreeNode(myCustomer.CustomerName,
        myTreeNodeArray);
        // Display the customer names with and Orange font.
        customerNode.ForeColor = Color.Orange;
        // Store the Customer object in the Tag property of the TreeNode.
        customerNode.Tag = myCustomer;
      myTreeView.Nodes[0].Nodes.Add(customerNode);
   }
}
Public Class Customer
   Public CustomerOrders As ArrayList
   Public CustomerName As String
   Public Sub New(myName As String)
      CustomerName = myName
      CustomerOrders = New ArrayList()
   End Sub
End Class

Public Class Order
   Public OrderID As String
   Public Sub New(myOrderID As String)
      Me.OrderID = myOrderID
   End Sub
End Class

Public Sub AddRootNodes()
   ' Add a root node to assign the customer nodes to.
   Dim rootNode As TreeNode
   rootNode = New TreeNode()
   rootNode.Text = "CustomerList"
   ' Add a main root treenode.
   myTreeView.Nodes.Add(rootNode)

   ' Add a root treenode for each Customer object in the ArrayList.
   Dim myCustomer As Customer
   For Each myCustomer In customerArray
      ' Add a child treenode for each Order object.
      Dim i As Integer = 0
      Dim myTreeNodeArray(4) As TreeNode
      Dim myOrder As Order
      For Each myOrder In  myCustomer.CustomerOrders
         myTreeNodeArray(i) = New TreeNode(myOrder.OrderID)
         i += 1
      Next myOrder
      Dim customerNode As New TreeNode(myCustomer.CustomerName, _
        myTreeNodeArray)
      ' Display the customer names with and Orange font.
      customerNode.ForeColor = Color.Orange
      ' Store the Customer object in the Tag property of the TreeNode.
      customerNode.Tag = myCustomer
      myTreeView.Nodes(0).Nodes.Add(customerNode)
   Next myCustomer
End Sub

Hinweise

Die maximale Anzahl von Zeichen, die ein TreeNode anzeigen kann, ist 259.The maximum number of characters that a TreeNode can display is 259. Wenn dieser Eigenschaft eine String zugeordnet ist, die mehr als 259 Zeichen aufweist, werden nur die ersten 259 Zeichen angezeigt.If a String that has more than 259 characters is assigned to this property, only the first 259 characters are displayed.

Diese Eigenschaft kann vom Benutzer nicht festgelegt werden, wenn die LabelEdit-Eigenschaft des übergeordneten TreeView auf falsefestgelegt ist.This property cannot be set by the user if the LabelEdit property of the parent TreeView is set to false. Die Alternative zum expliziten Festlegen dieser Eigenschaft besteht darin, den Struktur Knoten zu erstellen, indem Sie einen der TreeNode Konstruktoren verwenden, der über einen Zeichen folgen Parameter verfügt, der die Text-Eigenschaft darstellt.The alternative to explicitly setting this property is to create the tree node by using one of the TreeNode constructors that has a string parameter that represents the Text property. Wenn eine Bezeichnung angezeigt wird, wird Sie neben dem Bild TreeNode angezeigt.The label is displayed next to the TreeNode image, if one is displayed.

Gilt für:

Siehe auch