TreeNodeCollection.AddRange メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > TreeNodeCollection.AddRange メソッドの意味・解説 

TreeNodeCollection.AddRange メソッド

以前に作成したツリー ノードの配列をコレクションに追加します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

例外例外
例外の種類条件

ArgumentNullException

nodes が null 参照 (Visual Basic では Nothing) です。

ArgumentException

nodes が、別の TreeView の子になっています。

解説解説
使用例使用例

TreeNodeCollection を TreeView から一時的な Array にコピーし、この配列の内容を AddRange メソッドを使用して別の TreeView に追加するコード例を次に示します。元の TreeView の TreeNodeCollection は、Clear メソッドによって削除されます。この例は、TreeView コントロールが 2 つあり、一方には TreeNode オブジェクトのコレクションが設定されていることを前提にしています。

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からTreeNodeCollection.AddRange メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からTreeNodeCollection.AddRange メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からTreeNodeCollection.AddRange メソッド を検索

英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

TreeNodeCollection.AddRange メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TreeNodeCollection.AddRange メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS