Freigeben über


TreeNodeCollection.AddRange-Methode

Fügt der Auflistung ein Array von zuvor erstellten Strukturknoten hinzu.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Overridable Sub AddRange ( _
    nodes As TreeNode() _
)
'Usage
Dim instance As TreeNodeCollection
Dim nodes As TreeNode()

instance.AddRange(nodes)
public virtual void AddRange (
    TreeNode[] nodes
)
public:
virtual void AddRange (
    array<TreeNode^>^ nodes
)
public void AddRange (
    TreeNode[] nodes
)
public function AddRange (
    nodes : TreeNode[]
)

Parameter

  • nodes
    Ein Array von TreeNode-Objekten, die die der Auflistung hinzuzufügenden Strukturknoten darstellen.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentNullException

nodes ist NULL (Nothing in Visual Basic).

ArgumentException

nodes ist das untergeordnete Element einer anderen TreeView.

Hinweise

Die im nodes-Array enthaltenen TreeNode-Objekte werden am Ende der Auflistung angefügt.

Mit der AddRange-Methode können Sie der Auflistung eine Gruppe zuvor erstellter TreeNode-Objekte schnell hinzufügen, statt mithilfe der Add-Methode jeden TreeNode manuell hinzuzufügen.

Verwenden Sie die Remove-Methode, die RemoveAt-Methode oder die Clear-Methode, um einen zuvor hinzugefügten TreeNode zu entfernen.

Beispiel

Im folgenden Codebeispiel wird die TreeNodeCollection aus einer TreeView in ein temporäres Array kopiert. Anschließend wird mithilfe der AddRange-Methode der Inhalt des Arrays in eine andere TreeView kopiert. Die TreeNodeCollection aus der Quell-TreeView wird mithilfe der Clear-Methode gelöscht. Für dieses Beispiel ist es erforderlich, dass zwei TreeView-Steuerelemente vorhanden sind, wovon eines eine Auflistung von TreeNode-Objekten enthält.

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
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:
   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.get_Nodes();
    // Create an array of 'TreeNodes'.
    TreeNode myTreeNodeArray[] =
        new TreeNode[myTreeViewBase.get_Nodes().get_Count()];
    // Copy the tree nodes to the 'myTreeNodeArray' array.
    myTreeViewBase.get_Nodes().CopyTo(myTreeNodeArray, 0);
    // Remove all the tree nodes from the 'myTreeViewBase' TreeView.
    myTreeViewBase.get_Nodes().Clear();
    // Add the 'myTreeNodeArray' to the 'myTreeViewCustom' TreeView.
    myTreeViewCustom.get_Nodes().AddRange(myTreeNodeArray);
} //myButtonAddAllClick

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

TreeNodeCollection-Klasse
TreeNodeCollection-Member
System.Windows.Forms-Namespace
Add
CopyTo