다음을 통해 공유


TreeNodeCollection.AddRange 메서드

이전에 만든 트리 노드의 배열을 컬렉션에 추가합니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public Overridable Sub AddRange ( _
    nodes As TreeNode() _
)
‘사용 방법
Dim instance As TreeNodeCollection
Dim nodes As TreeNode()

instance.AddRange(nodes)
public virtual void AddRange (
    TreeNode[] nodes
)
public:
virtual void AddRange (
    array<TreeNode^>^ nodes
)
public void AddRange (
    TreeNode[] nodes
)
public function AddRange (
    nodes : TreeNode[]
)

매개 변수

  • nodes
    컬렉션에 추가할 트리 노드를 나타내는 TreeNode 개체의 배열입니다.

예외

예외 형식 조건

ArgumentNullException

nodes가 Null 참조(Visual Basic의 경우 Nothing)인 경우

ArgumentException

nodes가 다른 TreeView의 자식인 경우

설명

nodes 배열에 들어 있는 TreeNode 개체는 컬렉션의 끝에 추가됩니다.

Add 메서드를 사용하여 각 TreeNode을 컬렉션에 직접 추가하지 않고 AddRange 메서드를 사용하여 이전에 만든 TreeNode 개체의 그룹을 컬렉션에 신속하게 추가할 수 있습니다.

이전에 추가한 TreeNode을 제거하려면 Remove, RemoveAt 또는 Clear 메서드를 사용합니다.

예제

다음 코드 예제에서는 TreeView에서 임시 ArrayTreeNodeCollection을 복사한 다음 AddRange 메서드를 사용하여 배열의 내용을 다른 TreeView에 추가합니다. 소스 TreeViewTreeNodeCollectionClear 메서드를 사용하여 제거됩니다. 이 예제를 실행하려면 각각 하나의 TreeNode 개체 컬렉션을 포함하는 두 개의 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.
   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에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

TreeNodeCollection 클래스
TreeNodeCollection 멤버
System.Windows.Forms 네임스페이스
Add
CopyTo