TreeNodeCollection.AddRange(TreeNode[]) TreeNodeCollection.AddRange(TreeNode[]) TreeNodeCollection.AddRange(TreeNode[]) TreeNodeCollection.AddRange(TreeNode[]) Method

Definition

Die Auflistung hinzugefügt ein Array von zuvor erstellten Strukturknoten.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())

Parameter

nodes
TreeNode[]

Ein Array von TreeNode Objekte, die zur Auflistung hinzuzufügenden Strukturknoten darstellen.An array of TreeNode objects representing the tree nodes to add to the collection.

Ausnahmen

nodes das untergeordnete Element eines anderen TreeView.nodes is the child of another TreeView.

Beispiele

Im folgenden Codebeispiel Beispiel kopiert die TreeNodeCollection aus einer TreeView in ein temporäres Array, und fügt dann den Inhalt des Arrays in ein anderes TreeView mithilfe der AddRange Methode.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. Die TreeNodeCollection aus der Quelle TreeView deaktiviert ist, mit der Clear Methode.The TreeNodeCollection from the source TreeView is cleared using the Clear method. Dieses Beispiel erfordert, dass zwei TreeView Steuerelemente, mit der eine Auflistung von TreeNode Objekte.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

Hinweise

Die TreeNode Objekte in der nodes Array am Ende der Auflistung angefügt werden.The TreeNode objects contained in the nodes array are appended to the end of the collection.

Können Sie die AddRange hinzuzufügenden Methode schnell eine Gruppe von zuvor erstellten TreeNode -Objekte der Auflistung manuell hinzufügen TreeNode auf die Auflistung mit den Add Methode.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.

So entfernen Sie eine TreeNode , die Sie zuvor hinzugefügt haben, verwenden Sie die Remove, RemoveAt, oder Clear Methoden.To remove a TreeNode that you previously added, use the Remove, RemoveAt, or Clear methods.

Gilt für:

Siehe auch