TreeNodeCollection.AddRange(TreeNode[]) Método

Definición

Agrega a la colección una matriz de nodos de árbol anteriormente creados.Adds an array of previously created tree nodes to the collection.

public:
 virtual void AddRange(cli::array <System::Windows::Forms::TreeNode ^> ^ nodes);
public virtual void AddRange (System.Windows.Forms.TreeNode[] nodes);
abstract member AddRange : System.Windows.Forms.TreeNode[] -> unit
override this.AddRange : System.Windows.Forms.TreeNode[] -> unit
Public Overridable Sub AddRange (nodes As TreeNode())

Parámetros

nodes
TreeNode[]

Matriz de objetos TreeNode que representa los nodos de árbol que se van a agregar a la colección.An array of TreeNode objects representing the tree nodes to add to the collection.

Excepciones

nodes es null.nodes is null.

nodes es el elemento secundario del control TreeView.nodes is the child of another TreeView.

Ejemplos

En el ejemplo de código siguiente se copia el TreeNodeCollection de un TreeView en un Arraytemporal y, a continuación, se agrega el contenido de la matriz a otro TreeView mediante el método AddRange.The following code example copies the TreeNodeCollection from a TreeView to a temporary Array, and then adds the contents of the array to another TreeView using the AddRange method. El TreeNodeCollection del TreeView de origen se borra con el método Clear.The TreeNodeCollection from the source TreeView is cleared using the Clear method. Este ejemplo requiere que tenga dos controles TreeView, uno con una colección de objetos TreeNode.This example requires that you have two TreeView controls, one with a collection of TreeNode objects.

private:
   void MyButtonAddAllClick( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      
      // Get the 'myTreeNodeCollection' from the 'myTreeViewBase' TreeView.
      TreeNodeCollection^ myTreeNodeCollection = myTreeViewBase->Nodes;
      
      // Create an array of 'TreeNodes'.
      array<TreeNode^>^myTreeNodeArray = gcnew array<TreeNode^>(myTreeViewBase->Nodes->Count);
      
      // Copy the tree nodes to the 'myTreeNodeArray' array.
      myTreeViewBase->Nodes->CopyTo( myTreeNodeArray, 0 );
      
      // Remove all the tree nodes from the 'myTreeViewBase' TreeView.
      myTreeViewBase->Nodes->Clear();
      
      // Add the 'myTreeNodeArray' to the 'myTreeViewCustom' TreeView.
      myTreeViewCustom->Nodes->AddRange( myTreeNodeArray );
   }
private void MyButtonAddAllClick(object sender, EventArgs e)
{
   // Get the 'myTreeNodeCollection' from the 'myTreeViewBase' TreeView.
   TreeNodeCollection myTreeNodeCollection = myTreeViewBase.Nodes;
   // Create an array of 'TreeNodes'.
   TreeNode[] myTreeNodeArray = new TreeNode[myTreeViewBase.Nodes.Count];
   // Copy the tree nodes to the 'myTreeNodeArray' array.
   myTreeViewBase.Nodes.CopyTo(myTreeNodeArray,0);
   // Remove all the tree nodes from the 'myTreeViewBase' TreeView.
   myTreeViewBase.Nodes.Clear();
   // Add the 'myTreeNodeArray' to the 'myTreeViewCustom' TreeView.
   myTreeViewCustom.Nodes.AddRange(myTreeNodeArray);
}
Private Sub MyButtonAddAllClick(sender As Object, e As EventArgs)
   ' Get the 'myTreeNodeCollection' from the 'myTreeViewBase' TreeView.
   Dim myTreeNodeCollection As TreeNodeCollection = myTreeViewBase.Nodes
   ' Create an array of 'TreeNodes'.
   Dim myTreeNodeArray(myTreeViewBase.Nodes.Count-1) As TreeNode
   ' Copy the tree nodes to the 'myTreeNodeArray' array.
   myTreeViewBase.Nodes.CopyTo(myTreeNodeArray, 0)
   ' Remove all the tree nodes from the 'myTreeViewBase' TreeView.
   myTreeViewBase.Nodes.Clear()
   ' Add the 'myTreeNodeArray' to the 'myTreeViewCustom' TreeView.
      myTreeViewCustom.Nodes.AddRange(myTreeNodeArray)
End Sub

Comentarios

Los objetos TreeNode incluidos en la matriz de nodes se anexan al final de la colección.The TreeNode objects contained in the nodes array are appended to the end of the collection.

Puede usar el método AddRange para agregar rápidamente un grupo de objetos de TreeNode creados previamente a la colección en lugar de agregar manualmente cada TreeNode a la colección mediante el método Add.You can use the AddRange method to quickly add a group of previously created TreeNode objects to the collection instead of manually adding each TreeNode to the collection using the Add method.

Para quitar una TreeNode agregada anteriormente, use los métodos Remove, RemoveAto Clear.To remove a TreeNode that you previously added, use the Remove, RemoveAt, or Clear methods.

Se aplica a

Consulte también: