ListViewGroupCollection.AddRange 메서드

정의

컬렉션에 그룹을 여러 개 추가합니다.

오버로드

AddRange(ListViewGroup[])

그룹의 배열을 컬렉션에 추가합니다.

AddRange(ListViewGroupCollection)

컬렉션에 기존 ListViewGroupCollection의 그룹을 추가합니다.

AddRange(ListViewGroup[])

그룹의 배열을 컬렉션에 추가합니다.

public:
 void AddRange(cli::array <System::Windows::Forms::ListViewGroup ^> ^ groups);
public void AddRange (System.Windows.Forms.ListViewGroup[] groups);
member this.AddRange : System.Windows.Forms.ListViewGroup[] -> unit
Public Sub AddRange (groups As ListViewGroup())

매개 변수

groups
ListViewGroup[]

컬렉션에 추가할 값을 지정하는 ListViewGroup 형식의 배열입니다.

예외

ListViewItem을 소유하고 있는 컨트롤 이외의 ListView 컨트롤에 속한 ListViewGroupCollection이 하나 이상 있는 그룹이 groups에 하나 이상 포함된 경우

ListView 이 컬렉션이 할당된 값은 가상 모드입니다.

예제

다음 예제에서는 하는 방법을 AddRange 메서드를 구성 하는 애플리케이션에서 사용할 수 있습니다 ListView 항목 세부 정보 뷰에서 하위 항목 값입니다. 이러한 형태의 그룹화 Windows 탐색기에서 사용 되는 그룹화 하는 것과 비슷합니다. 예제에서는 그룹을 동적으로 생성 됩니다. 각 하위 항목 열에 대 한 각 하위 항목 고유 값에 대해 하나의 그룹이 만들어집니다. 부모 항목 열에 대 한 각 고유 첫 문자에 대 한 하나의 그룹이 만들어집니다. 각 열에 대해 만든 그룹은 초기 문자를 하위 항목 텍스트와 함께 해시 테이블에 저장 됩니다. 열 머리글을 클릭할 때는 ListViewGroupCollection 지워집니다. 클릭 한 열에 해당 하는 해시 테이블 검색 됩니다 하 고 각 항목은 해당 그룹에 할당 됩니다. 해시 테이블에 있는 그룹의 정렬 된 배열에 추가 되는 마지막으로 ListViewGroupCollection합니다.

전체 예제를 참조 하세요.를 ListViewGroupCollection 개요 항목을 참조 합니다.

   // Sets myListView to the groups created for the specified column.
private:
   void SetGroups(int column)
   {
      // Remove the current groups.
      myListView->Groups->Clear();

      // Retrieve the hash table corresponding to the column.
      Hashtable^ groups = dynamic_cast<Hashtable^>(groupTables[column]);

      // Copy the groups for the column to an array.
      array<ListViewGroup^>^ groupsArray = gcnew array<ListViewGroup^>(groups->Count);
      groups->Values->CopyTo(groupsArray, 0);

      // Sort the groups and add them to myListView.
      Array::Sort(groupsArray, gcnew ListViewGroupSorter(myListView->Sorting));
      myListView->Groups->AddRange(groupsArray);

      // Iterate through the items in myListView, assigning each 
      // one to the appropriate group.
      IEnumerator^ myEnum = myListView->Items->GetEnumerator();
      while (myEnum->MoveNext())
      {
         ListViewItem^ item = safe_cast<ListViewItem^>(myEnum->Current);
         // Retrieve the subitem text corresponding to the column.
         String^ subItemText = item->SubItems[column]->Text;

         // For the Title column, use only the first letter.
         if (column == 0) 
         {
            subItemText = subItemText->Substring(0, 1);
         }

         // Assign the item to the matching group.
         item->Group = dynamic_cast<ListViewGroup^>(groups[subItemText]);
      }
   }
// Sets myListView to the groups created for the specified column.
private void SetGroups(int column)
{
    // Remove the current groups.
    myListView.Groups.Clear();

    // Retrieve the hash table corresponding to the column.
    Hashtable groups = (Hashtable)groupTables[column];

    // Copy the groups for the column to an array.
    ListViewGroup[] groupsArray = new ListViewGroup[groups.Count];
    groups.Values.CopyTo(groupsArray, 0);

    // Sort the groups and add them to myListView.
    Array.Sort(groupsArray, new ListViewGroupSorter(myListView.Sorting));
    myListView.Groups.AddRange(groupsArray);

    // Iterate through the items in myListView, assigning each 
    // one to the appropriate group.
    foreach (ListViewItem item in myListView.Items)
    {
        // Retrieve the subitem text corresponding to the column.
        string subItemText = item.SubItems[column].Text;

        // For the Title column, use only the first letter.
        if (column == 0) 
        {
            subItemText = subItemText.Substring(0, 1);
        }

        // Assign the item to the matching group.
        item.Group = (ListViewGroup)groups[subItemText];
    }
}
' Sets myListView to the groups created for the specified column.
Private Sub SetGroups(column As Integer)
    ' Remove the current groups.
    myListView.Groups.Clear()
    
    ' Retrieve the hash table corresponding to the column.
    Dim groups As Hashtable = CType(groupTables(column), Hashtable)
    
    ' Copy the groups for the column to an array.
    Dim groupsArray(groups.Count - 1) As ListViewGroup
    groups.Values.CopyTo(groupsArray, 0)
    
    ' Sort the groups and add them to myListView.
    Array.Sort(groupsArray, New ListViewGroupSorter(myListView.Sorting))
    myListView.Groups.AddRange(groupsArray)
    
    ' Iterate through the items in myListView, assigning each 
    ' one to the appropriate group.
    Dim item As ListViewItem
    For Each item In myListView.Items
        ' Retrieve the subitem text corresponding to the column.
        Dim subItemText As String = item.SubItems(column).Text
        
        ' For the Title column, use only the first letter.
        If column = 0 Then
            subItemText = subItemText.Substring(0, 1)
        End If 

        ' Assign the item to the matching group.
        item.Group = CType(groups(subItemText), ListViewGroup)
    Next item
End Sub

설명

이 버전의 사용을 AddRange 그룹 컬렉션에 측정값 그룹의 배열을 추가 하는 방법입니다. 이 메서드는 여러 만들면 유용 ListViewGroup 개체 및 단일 메서드 호출을 사용 하 여 컬렉션에 추가할 합니다. 컬렉션에 개별 그룹을 추가 하려면 사용 된 Add 메서드.

항목을 그룹화 하는 여러 방법을 제공 하려는 경우이 메서드는 유용도 ListView 제어 합니다. 이 작업을 수행 하려면 여러 그룹 배열을 만듭니다. 그룹화를 변경 하려면 먼저 사용 합니다 Clear 컬렉션에서 모든 그룹을 제거 하 고 사용 하 여 메서드를 AddRange 그룹의 다른 배열을 추가 하는 방법입니다.

달리는 Add 메서드는 AddRange 메서드가 추가 되는 그룹 컬렉션에 이미 있는지 여부를 결정할 수 있는 반환 값이 없는 합니다. 이 정보를 필요로 하는 경우 사용 합니다 Contains 메서드를 사용 하기 전에 AddRange 메서드.

추가 정보

적용 대상

AddRange(ListViewGroupCollection)

컬렉션에 기존 ListViewGroupCollection의 그룹을 추가합니다.

public:
 void AddRange(System::Windows::Forms::ListViewGroupCollection ^ groups);
public void AddRange (System.Windows.Forms.ListViewGroupCollection groups);
member this.AddRange : System.Windows.Forms.ListViewGroupCollection -> unit
Public Sub AddRange (groups As ListViewGroupCollection)

매개 변수

groups
ListViewGroupCollection

컬렉션에 추가할 그룹이 포함된 ListViewGroupCollection입니다.

예외

ListViewItem을 소유하고 있는 컨트롤 이외의 ListView 컨트롤에 속한 ListViewGroupCollection이 하나 이상 있는 그룹이 groups에 하나 이상 포함된 경우

ListView 이 컬렉션이 할당된 값은 가상 모드입니다.

설명

이 버전을 사용 합니다 AddRange 의 요소를 추가 하는 방법을 ListViewGroupCollection 통해 검색 하는 ListView.Groups 다른 속성 ListView 컨트롤.

달리는 Add 메서드는 AddRange 메서드가 추가 되는 그룹 컬렉션에 이미 있는지 여부를 결정할 수 있는 반환 값이 없는 합니다. 이 정보를 필요로 하는 경우 사용 합니다 Contains 메서드를 사용 하기 전에 AddRange 메서드.

적용 대상