TreeNode.Text TreeNode.Text TreeNode.Text TreeNode.Text Property

Definición

Obtiene o establece el texto mostrado en la etiqueta del nodo de árbol.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

Valor de propiedad

El texto mostrado en la etiqueta del nodo de árbol.The text displayed in the label of the tree node.

Ejemplos

En el ejemplo de código siguiente se crea un nodo de árbol raíz para asignarle a secundarios de nodos de árbol.The following code example creates a root tree node to assign child tree nodes to. Un nodo de árbol secundarios para cada Customer objeto en un ArrayList se agrega al nodo de árbol raíz, así como un nodo de árbol secundarios para cada Order objeto asignado a la Customer objeto.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. El Customer se asigna a la Tag propiedad y los nodos de árbol que representa Customer los objetos se muestran con Orange texto.The Customer object is assigned to the Tag property, and the tree nodes representing Customer objects are displayed with Orange text. En este ejemplo requiere que haya un Customer y Order objeto definido, un TreeView control en un Formy un ArrayList denominado customerArray que contiene Customer objetos.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 'New
End Class 'Customer

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

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

Comentarios

El número máximo de caracteres que un TreeNode puede mostrar es 259.The maximum number of characters that a TreeNode can display is 259. Si un String que tiene más de 259 caracteres está asignado a esta propiedad, se muestran solo los primeros 259 caracteres.If a String that has more than 259 characters is assigned to this property, only the first 259 characters are displayed.

Esta propiedad no se puede establecer por el usuario si la LabelEdit propiedad del elemento primario TreeView está establecido en false.This property cannot be set by the user if the LabelEdit property of the parent TreeView is set to false. La alternativa a establecer explícitamente esta propiedad es para crear el nodo de árbol mediante uno de los TreeNode constructores que tiene un parámetro de cadena que representa el Text propiedad.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. La etiqueta se muestra junto a la TreeNode la imagen, si se muestra ninguno.The label is displayed next to the TreeNode image, if one is displayed.

Se aplica a

Consulte también: