TreeNodeCollection.Clear TreeNodeCollection.Clear TreeNodeCollection.Clear TreeNodeCollection.Clear Method

Definition

Entfernt alle Strukturknoten aus der Auflistung.Removes all tree nodes from the collection.

public:
 virtual void Clear();
public virtual void Clear ();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Overridable Sub Clear ()

Implementiert

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

Sie können diese Methode verwenden, um die gesamte Auflistung von Strukturknoten aus der Strukturansicht zu löschen.You can use this method to clear the entire collection of tree nodes from a tree view.

Um einen einzelnen Strukturknoten aus der Auflistung zu entfernen, verwenden die Remove oder RemoveAt Methoden.To remove an individual tree node from the collection, use the Remove or RemoveAt methods.

Hinzufügen neuer TreeNode Objekte der Auflistung verwenden, die Add, AddRange, oder Insert Methoden.To add new TreeNode objects to the collection, use the Add, AddRange, or Insert methods.

Gilt für: