Share via


ListViewItem.Group Özellik

Tanım

Öğenin atandığı grubu alır veya ayarlar.

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

Özellik Değeri

Öğenin ListViewGroup atandığı öğe.

Örnekler

Aşağıdaki kod örneği, özelliğin Group ayrıntılar görünümünde öğeleri alt öğe değerine göre düzenleyen ListView bir uygulamada nasıl kullanılabileceğini gösterir. Bu gruplandırma biçimi, Windows Gezgini'nde kullanılan gruplandırmaya benzer. Örnekte gruplar dinamik olarak oluşturulur. Her alt sütun için, her benzersiz alt değer için bir grup oluşturulur. Üst öğe sütunu için, her benzersiz ilk harf için bir grup oluşturulur. Her sütun için oluşturulan gruplar, alt metin veya ilk harfle birlikte bir karma tabloda depolanır. Bir sütun üst bilgisine tıklandığında, bu sütuna karşılık gelen karma tablosu alınır. Ardından, bu sütunun alt metin değerleri, her öğe için doğru grubu almak üzere karma tablo anahtarları olarak kullanılır. Öğe daha sonra özelliği kullanılarak Group gruba atanır.

Bu kod örneği, özelliği için ListView.Groups sağlanan daha büyük bir örneğin parçasıdır.

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

Açıklamalar

Bir öğenin ait olduğu grubu ayarlamak için bu özelliği kullanın. Grubu oluşturucuda ListViewItem da ayarlayabilir veya çalışma zamanında grup üyeliğini değiştirmek için bu özelliği kullanabilirsiniz. Bu özelliği olarak null ayarlarsanız ve koleksiyonda ListView.Groups gruplar varsa, öğe "DefaultGroupSystem.Windows.Forms" üst bilgi etiketine sahip varsayılan grupta görünür. Varsayılan grup koleksiyonda ListView.Groups yer almadığından değiştirilemez. Tüm öğelerin gruplara düzgün şekilde eklendiğinden emin olmak için hata ayıklamada öncelikli olarak yararlıdır.

Not

ListView grupları yalnızca Windows XP ve Windows Server 2003 ailesinde (Windows XP Home Edition, Windows XP Professional, Windows Server 2003) kullanılabilir. Daha fazla bilgi için genel bakış konusuna ListViewGroup bakın.

Şunlara uygulanır

Ayrıca bkz.