ListViewItem.Group 속성

정의

항목을 할당할 그룹을 가져오거나 설정합니다.

public:
 property System::Windows::Forms::ListViewGroup ^ Group { System::Windows::Forms::ListViewGroup ^ get(); void set(System::Windows::Forms::ListViewGroup ^ value); };
public System.Windows.Forms.ListViewGroup Group { get; set; }
public System.Windows.Forms.ListViewGroup? Group { get; set; }
member this.Group : System.Windows.Forms.ListViewGroup with get, set
Public Property Group As ListViewGroup

속성 값

항목을 할당할 ListViewGroup입니다.

예제

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

이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ListView.Groups 속성입니다.

   // 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

설명

항목이 속한 그룹을 설정하려면 이 속성을 사용합니다. 생성자에서 ListViewItem 그룹을 설정하거나 이 속성을 사용하여 런타임에 그룹 멤버 자격을 수정할 수도 있습니다. 이 속성을 null 로 설정하고 컬렉션에 ListView.Groups 그룹이 있는 경우 항목은 "DefaultGroupSystem.Windows.Forms" 헤더 레이블이 있는 기본 그룹에 표시됩니다. 기본 그룹에 포함 되어 있지는 ListView.Groups 컬렉션을 변경할 수 없습니다. 모든 항목이 있는 그룹에 올바르게 추가 되었는지 확인 하는 디버깅에 주로 유용 합니다.

참고

ListView 그룹은 Windows XP 및 Windows Server 2003 제품군(Windows XP Home Edition, Windows XP Professional, Windows Server 2003)에서만 사용할 수 있습니다. 자세한 내용은 ListViewGroup 개요 항목을 참조하십시오.

적용 대상

추가 정보