ListViewGroupCollection.AddRange Yöntem

Tanım

Koleksiyona birden çok grup ekler.

Aşırı Yüklemeler

AddRange(ListViewGroup[])

Koleksiyona bir grup dizisi ekler.

AddRange(ListViewGroupCollection)

Var olan ListViewGroupCollection bir gruptaki grupları koleksiyona ekler.

AddRange(ListViewGroup[])

Koleksiyona bir grup dizisi ekler.

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())

Parametreler

groups
ListViewGroup[]

Koleksiyona eklenecek grupları belirten tür ListViewGroup dizisi.

Özel durumlar

groups, bu denetime sahip ListViewGroupCollectionolandan başka bir denetime ait olan en az ListViewItem bir ListView grubu içerir.

ListView Bu koleksiyonun atandığı sanal moddadır.

Örnekler

Aşağıdaki örnek, ayrıntılar görünümünde öğeleri alt öğe değerine göre düzenleyen ListView bir uygulamada yönteminin nasıl AddRange 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, ListViewGroupCollection seçeneği temizlenir. Tıklanan sütuna karşılık gelen karma tablo daha sonra alınır ve her öğe uygun gruba atanır. Son olarak, karma tablosundaki grupların sıralanmış dizisi öğesine ListViewGroupCollectioneklenir.

Tam örnek için genel bakış başvuru konusuna ListViewGroupCollection bakın.

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

Grup koleksiyonuna AddRange bir grup dizisi eklemek için yönteminin bu sürümünü kullanın. Bu yöntem, birden çok ListViewGroup nesne oluşturduğunuzda ve bunları tek bir yöntem çağrısıyla koleksiyona eklemek istediğinizde kullanışlıdır. Koleksiyona tek tek gruplar eklemek için yöntemini kullanın Add .

Bu yöntem, bir ListView denetimdeki öğeleri gruplandırmak için birden çok yol sağlamak istediğinizde de yararlıdır. Bunu yapmak için birden çok grup dizisi oluşturun. Gruplandırmayı değiştirmek için önce yöntemini kullanarak Clear koleksiyondaki tüm grupları kaldırın, ardından yöntemini kullanarak AddRange farklı bir grup dizisi ekleyin.

yönteminden Add farklı olarak yönteminin AddRange , eklenen bir grubun koleksiyonda zaten olup olmadığını belirlemek için kullanılabilecek bir dönüş değeri yoktur. Bu bilgiye ihtiyacınız varsa yöntemini kullanmadan AddRange önce yöntemini kullanınContains.

Ayrıca bkz.

Şunlara uygulanır

AddRange(ListViewGroupCollection)

Var olan ListViewGroupCollection bir gruptaki grupları koleksiyona ekler.

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)

Parametreler

groups
ListViewGroupCollection

ListViewGroupCollection Koleksiyona eklenecek grupları içeren.

Özel durumlar

groups, bu denetime sahip ListViewGroupCollectionolandan başka bir denetime ait olan en az ListViewItem bir ListView grubu içerir.

ListView Bu koleksiyonun atandığı sanal moddadır.

Açıklamalar

Farklı ListView bir ListViewGroupCollection denetimin AddRange özelliği aracılığıyla aldığınız öğelerini eklemek için yönteminin ListView.Groups bu sürümünü kullanın.

yönteminden Add farklı olarak yönteminin AddRange , eklenen bir grubun koleksiyonda zaten olup olmadığını belirlemek için kullanılabilecek bir dönüş değeri yoktur. Bu bilgiye ihtiyacınız varsa yöntemini kullanmadan AddRange önce yöntemini kullanınContains.

Şunlara uygulanır