TreeNodeCollection.AddRange(TreeNode[]) Metoda

Definicja

Dodaje tablicę wcześniej utworzonych węzłów drzewa do kolekcji.

public:
 virtual void AddRange(cli::array <System::Windows::Forms::TreeNode ^> ^ nodes);
public:
 virtual void AddRange(... cli::array <System::Windows::Forms::TreeNode ^> ^ nodes);
public virtual void AddRange (System.Windows.Forms.TreeNode[] nodes);
public virtual void AddRange (params 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())
Public Overridable Sub AddRange (ParamArray nodes As TreeNode())

Parametry

nodes
TreeNode[]

Tablica TreeNode obiektów reprezentujących węzły drzewa do dodania do kolekcji.

Wyjątki

nodes to null.

nodes jest elementem podrzędnym innego TreeViewelementu .

Przykłady

Poniższy przykład kodu kopiuje element TreeNodeCollection z elementu TreeView do tymczasowego Array, a następnie dodaje zawartość tablicy do innej TreeView przy użyciu AddRange metody . TreeView Źródło TreeNodeCollection jest czyszczone przy użyciu Clear metody . W tym przykładzie wymagane są dwie TreeView kontrolki z kolekcją TreeNode obiektów.

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

Uwagi

Obiekty TreeNode zawarte w tablicy nodes są dołączane na końcu kolekcji.

Za pomocą AddRange metody można szybko dodać grupę wcześniej utworzonych TreeNode obiektów do kolekcji zamiast ręcznie dodawać je TreeNode do kolekcji przy użyciu Add metody .

Aby usunąć TreeNode wcześniej dodany element, użyj Removemetod , RemoveAtlub Clear .

Dotyczy

Zobacz też