Sdílet prostřednictvím


ListViewGroupCollection.AddRange Metoda

Definice

Přidá do kolekce více skupin.

Přetížení

Name Description
AddRange(ListViewGroup[])

Přidá do kolekce pole skupin.

AddRange(ListViewGroupCollection)

Přidá skupiny v existující ListViewGroupCollection kolekci.

AddRange(ListViewGroup[])

Zdroj:
ListViewGroupCollection.cs
Zdroj:
ListViewGroupCollection.cs
Zdroj:
ListViewGroupCollection.cs
Zdroj:
ListViewGroupCollection.cs
Zdroj:
ListViewGroupCollection.cs

Přidá do kolekce pole skupin.

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

Parametry

groups
ListViewGroup[]

Pole typu ListViewGroup , které určuje skupiny, které se mají přidat do kolekce.

Výjimky

groups obsahuje alespoň jednu skupinu s alespoň jednou ListViewItem , která patří do jiného ListView ovládacího prvku než do skupiny, která tuto ListViewGroupCollectionskupinu vlastní .

Tato ListView kolekce je přiřazená ve virtuálním režimu.

Příklady

Následující příklad ukazuje, jak lze metodu AddRange použít v aplikaci, která uspořádá ListView položky podle hodnoty subitem v zobrazení podrobností. Tato forma seskupení se podobá seskupování použitému v Průzkumníku Windows. V tomto příkladu se skupiny vytvářejí dynamicky. Pro každý sloupec podsítě se vytvoří jedna skupina pro každou jedinečnou hodnotu podsítě. Pro sloupec nadřazené položky se vytvoří jedna skupina pro každé jedinečné počáteční písmeno. Skupiny vytvořené pro každý sloupec jsou uloženy v tabulce hash spolu s textem subitem nebo počátečním písmenem. Když kliknete na záhlaví sloupce, vymaže se ListViewGroupCollection . Potom se načte tabulka hash odpovídající kliknutí na sloupec a každá položka se přiřadí příslušné skupině. Nakonec se do ListViewGroupCollectiontabulky hash přidá seřazené pole skupin v tabulce hash .

Úplný příklad najdete v referenčním tématu přehledu 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

Poznámky

Tato verze AddRange metody slouží k přidání pole skupin do kolekce skupin. Tato metoda je užitečná při vytváření více ListViewGroup objektů a chcete je přidat do kolekce jedním voláním metody. Pokud chcete do kolekce přidat jednotlivé skupiny, použijte metodu Add .

Tato metoda je také užitečná, pokud chcete poskytnout více způsobů, jak seskupit položky v ovládacím ListView prvku. Uděláte to tak, že vytvoříte více polí skupin. Pokud chcete změnit seskupení, nejprve pomocí Clear metody odeberte všechny skupiny z kolekce a pak pomocí AddRange metody přidejte jiné pole skupin.

Add Na rozdíl od metody nemá metoda návratovou hodnotu, kterou lze použít k určení, AddRange zda je přidaná skupina již v kolekci. Pokud tyto informace potřebujete, použijte metodu ContainsAddRange před použitím metody.

Viz také

Platí pro

AddRange(ListViewGroupCollection)

Zdroj:
ListViewGroupCollection.cs
Zdroj:
ListViewGroupCollection.cs
Zdroj:
ListViewGroupCollection.cs
Zdroj:
ListViewGroupCollection.cs
Zdroj:
ListViewGroupCollection.cs

Přidá skupiny v existující ListViewGroupCollection kolekci.

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)

Parametry

groups
ListViewGroupCollection

A ListViewGroupCollection obsahující skupiny, které se mají přidat do kolekce.

Výjimky

groups obsahuje alespoň jednu skupinu s alespoň jednou ListViewItem , která patří do jiného ListView ovládacího prvku než do skupiny, která tuto ListViewGroupCollectionskupinu vlastní .

Tato ListView kolekce je přiřazená ve virtuálním režimu.

Poznámky

Tuto verzi AddRange metody použijte k přidání prvků ListViewGroupCollection , které načítáte prostřednictvím ListView.Groups vlastnosti jiného ListView ovládacího prvku.

Add Na rozdíl od metody nemá metoda návratovou hodnotu, kterou lze použít k určení, AddRange zda je přidaná skupina již v kolekci. Pokud tyto informace potřebujete, použijte metodu ContainsAddRange před použitím metody.

Platí pro