TreeNodeCollection.AddRange メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)



nodes 配列に格納されている TreeNode オブジェクトが、コレクションの末尾に追加されます。
AddRange メソッドを使用すると、Add メソッドを使用して TreeNode を 1 つずつ手動でコレクションに追加するのではなく、以前に作成した TreeNode オブジェクトのグループをすばやくコレクションに追加できます。

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からTreeNodeCollection.AddRange メソッドを検索する場合は、下記のリンクをクリックしてください。

- TreeNodeCollection.AddRange メソッドのページへのリンク