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


以前に作成したツリー ノードの配列をコレクションに追加します。Adds an array of previously created tree nodes to the collection.

 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())



コレクションに追加するツリー ノードを表す TreeNode オブジェクトの配列。An array of TreeNode objects representing the tree nodes to add to the collection.


nodes が、別の TreeView の子になっています。nodes is the child of another TreeView.

次のコード例ではTreeNodeCollection 、をTreeViewから一時Arrayにコピーし、 AddRangeメソッドを使用して配列の内容TreeViewを別のに追加します。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. ClearソースTreeNodeCollection からのは、メソッドを使用して消去されます。TreeViewThe TreeNodeCollection from the source TreeView is cleared using the Clear method. この例では、オブジェクトのTreeView TreeNodeコレクションを持つ2つのコントロールが必要です。This example requires that you have two TreeView controls, one with a collection of TreeNode objects.

   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.
      // 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.
   // Remove all the tree nodes from the 'myTreeViewBase' TreeView.
   // Add the 'myTreeNodeArray' to the 'myTreeViewCustom' TreeView.
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.
   ' Add the 'myTreeNodeArray' to the 'myTreeViewCustom' TreeView.
End Sub


配列に含まれるTreeNodeオブジェクトは、コレクションの末尾に追加さnodesれます。The TreeNode objects contained in the nodes array are appended to the end of the collection.

メソッドを使用AddRangeすると、前に作成したTreeNodeオブジェクトのグループをコレクションにすばやく追加できます。 TreeNodeただし、 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.

以前に追加TreeNodeしたを削除するにはRemove、メソッド、 Clearメソッド、またはメソッドを使用RemoveAtします。To remove a TreeNode that you previously added, use the Remove, RemoveAt, or Clear methods.