Sdílet prostřednictvím


ListViewGroup Konstruktory

Definice

Inicializuje novou instanci ListViewGroup třídy.

Přetížení

ListViewGroup()

Inicializuje novou instanci ListViewGroup třídy pomocí výchozího textu záhlaví "ListViewGroup" a výchozí zarovnání záhlaví vlevo.

ListViewGroup(String)

Inicializuje novou instanci ListViewGroup třídy pomocí zadané hodnoty pro inicializaci Header vlastnosti a pomocí výchozího zarovnání levého záhlaví.

ListViewGroup(String, String)

Inicializuje novou instanci ListViewGroup třídy pomocí zadaných hodnot pro inicializaci Name a Header vlastnosti.

ListViewGroup(String, HorizontalAlignment)

Inicializuje novou instanci ListViewGroup třídy pomocí zadaného textu záhlaví a zadané zarovnání záhlaví.

ListViewGroup()

Inicializuje novou instanci ListViewGroup třídy pomocí výchozího textu záhlaví "ListViewGroup" a výchozí zarovnání záhlaví vlevo.

public:
 ListViewGroup();
public ListViewGroup ();
Public Sub New ()

Platí pro

ListViewGroup(String)

Inicializuje novou instanci ListViewGroup třídy pomocí zadané hodnoty pro inicializaci Header vlastnosti a pomocí výchozího zarovnání levého záhlaví.

public:
 ListViewGroup(System::String ^ header);
public ListViewGroup (string header);
public ListViewGroup (string? header);
new System.Windows.Forms.ListViewGroup : string -> System.Windows.Forms.ListViewGroup
Public Sub New (header As String)

Parametry

header
String

Text, který se má zobrazit pro záhlaví skupiny.

Platí pro

ListViewGroup(String, String)

Inicializuje novou instanci ListViewGroup třídy pomocí zadaných hodnot pro inicializaci Name a Header vlastnosti.

public:
 ListViewGroup(System::String ^ key, System::String ^ headerText);
public ListViewGroup (string key, string headerText);
public ListViewGroup (string? key, string? headerText);
new System.Windows.Forms.ListViewGroup : string * string -> System.Windows.Forms.ListViewGroup
Public Sub New (key As String, headerText As String)

Parametry

key
String

Počáteční hodnota Name vlastnosti.

headerText
String

Počáteční hodnota Header vlastnosti.

Platí pro

ListViewGroup(String, HorizontalAlignment)

Inicializuje novou instanci ListViewGroup třídy pomocí zadaného textu záhlaví a zadané zarovnání záhlaví.

public:
 ListViewGroup(System::String ^ header, System::Windows::Forms::HorizontalAlignment headerAlignment);
public ListViewGroup (string header, System.Windows.Forms.HorizontalAlignment headerAlignment);
public ListViewGroup (string? header, System.Windows.Forms.HorizontalAlignment headerAlignment);
new System.Windows.Forms.ListViewGroup : string * System.Windows.Forms.HorizontalAlignment -> System.Windows.Forms.ListViewGroup
Public Sub New (header As String, headerAlignment As HorizontalAlignment)

Parametry

header
String

Text, který se má zobrazit pro záhlaví skupiny.

headerAlignment
HorizontalAlignment

Jedna z HorizontalAlignment hodnot, které určují zarovnání textu záhlaví.

Příklady

Následující příklad kódu ukazuje, jak ListViewGroup lze konstruktor použít v aplikaci, která uspořádá ListView položky podle hodnoty podnabídky v zobrazení podrobností. Tato forma seskupení se podobá seskupení použitému v Windows Exploreru. 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 podsítě nebo počátečním písmenem. Když kliknete na záhlaví sloupce, použije se tato textová hodnota ke spárování položek se skupinami pro příslušný sloupec.

Úplný příklad najdete v referenčním tématu přehledu ListViewGroup .

   // Creates a Hashtable object with one entry for each unique
   // subitem value (or initial letter for the parent item)
   // in the specified column.
private:
   Hashtable^ CreateGroupsTable(int column)
   {
      // Create a Hashtable object.
      Hashtable^ groups = gcnew Hashtable();

      // Iterate through the items in myListView.
      IEnumerator^ myEnum1 = myListView->Items->GetEnumerator();
      while (myEnum1->MoveNext())
      {
         ListViewItem^ item = safe_cast<ListViewItem^>(myEnum1->Current);
         // Retrieve the text value for the column.
         String^ subItemText = item->SubItems[column]->Text;

         // Use the initial letter instead if it is the first column.
         if (column == 0) 
         {
            subItemText = subItemText->Substring(0, 1);
         }

         // If the groups table does not already contain a group
         // for the subItemText value, add a new group using the 
         // subItemText value for the group header and Hashtable key.
         if (!groups->Contains(subItemText))
         {
            groups->Add( subItemText, gcnew ListViewGroup(subItemText, 
               HorizontalAlignment::Left) );
         }
      }

      // Return the Hashtable object.
      return groups;
   }
// Creates a Hashtable object with one entry for each unique
// subitem value (or initial letter for the parent item)
// in the specified column.
private Hashtable CreateGroupsTable(int column)
{
    // Create a Hashtable object.
    Hashtable groups = new Hashtable();

    // Iterate through the items in myListView.
    foreach (ListViewItem item in myListView.Items)
    {
        // Retrieve the text value for the column.
        string subItemText = item.SubItems[column].Text;

        // Use the initial letter instead if it is the first column.
        if (column == 0) 
        {
            subItemText = subItemText.Substring(0, 1);
        }

        // If the groups table does not already contain a group
        // for the subItemText value, add a new group using the 
        // subItemText value for the group header and Hashtable key.
        if (!groups.Contains(subItemText))
        {
            groups.Add( subItemText, new ListViewGroup(subItemText, 
                HorizontalAlignment.Left) );
        }
    }

    // Return the Hashtable object.
    return groups;
}
' Creates a Hashtable object with one entry for each unique
' subitem value (or initial letter for the parent item)
' in the specified column.
Private Function CreateGroupsTable(column As Integer) As Hashtable
    ' Create a Hashtable object.
    Dim groups As New Hashtable()
    
    ' Iterate through the items in myListView.
    Dim item As ListViewItem
    For Each item In myListView.Items
        ' Retrieve the text value for the column.
        Dim subItemText As String = item.SubItems(column).Text
        
        ' Use the initial letter instead if it is the first column.
        If column = 0 Then
            subItemText = subItemText.Substring(0, 1)
        End If 

        ' If the groups table does not already contain a group
        ' for the subItemText value, add a new group using the 
        ' subItemText value for the group header and Hashtable key.
        If Not groups.Contains(subItemText) Then
            groups.Add( subItemText, New ListViewGroup(subItemText, _
                HorizontalAlignment.Left) )
        End If
    Next item
    
    ' Return the Hashtable object.
    Return groups
End Function 'CreateGroupsTable

Platí pro