ListViewGroup Costruttori

Definizione

Inizializza una nuova istanza della classe ListViewGroup.

Overload

ListViewGroup()

Consente di inizializzare una nuova istanza della classe ListViewGroup utilizzando il testo predefinito dell'intestazione, "ListViewGroup", e l'allineamento predefinito a sinistra dell'intestazione.

ListViewGroup(String)

Inizializza una nuova istanza della classe ListViewGroup utilizzando il valore specificato per inizializzare la proprietà Header e utilizzando l'allineamento a sinistra predefinito dell'intestazione.

ListViewGroup(String, String)

Inizializza una nuova istanza della classe ListViewGroup utilizzando il valore specificato per inizializzare le proprietà Name eHeader.

ListViewGroup(String, HorizontalAlignment)

Consente di inizializzare una nuova istanza della classe ListViewGroup utilizzando il testo dell'intestazione specificato e l'allineamento dell'intestazione specificato.

ListViewGroup()

Consente di inizializzare una nuova istanza della classe ListViewGroup utilizzando il testo predefinito dell'intestazione, "ListViewGroup", e l'allineamento predefinito a sinistra dell'intestazione.

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

Si applica a

ListViewGroup(String)

Inizializza una nuova istanza della classe ListViewGroup utilizzando il valore specificato per inizializzare la proprietà Header e utilizzando l'allineamento a sinistra predefinito dell'intestazione.

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)

Parametri

header
String

Testo da visualizzare per l'intestazione del gruppo.

Si applica a

ListViewGroup(String, String)

Inizializza una nuova istanza della classe ListViewGroup utilizzando il valore specificato per inizializzare le proprietà Name eHeader.

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)

Parametri

key
String

Valore iniziale della proprietà Name.

headerText
String

Valore iniziale della proprietà Header.

Si applica a

ListViewGroup(String, HorizontalAlignment)

Consente di inizializzare una nuova istanza della classe ListViewGroup utilizzando il testo dell'intestazione specificato e l'allineamento dell'intestazione specificato.

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)

Parametri

header
String

Testo da visualizzare per l'intestazione del gruppo.

headerAlignment
HorizontalAlignment

Uno dei valori di HorizontalAlignment che specifica l'allineamento del testo dell'intestazione.

Esempio

Nell'esempio di codice seguente viene illustrato come usare il ListViewGroup costruttore in un'applicazione che organizza gli ListView elementi in base al valore dell'elemento secondario nella visualizzazione dettagli. Questa forma di raggruppamento è simile al raggruppamento usato in Windows Explorer. Nell'esempio i gruppi vengono creati in modo dinamico. Per ogni colonna dell'elemento secondario viene creato un gruppo per ogni valore di sottoelemento univoco. Per la colonna elemento padre viene creato un gruppo per ogni lettera iniziale univoca. I gruppi creati per ogni colonna vengono archiviati in una tabella hash insieme al testo dell'elemento secondario o alla lettera iniziale. Quando si fa clic su un'intestazione di colonna, questo valore di testo viene usato per trovare la corrispondenza tra elementi e gruppi per la colonna appropriata.

Per l'esempio completo, vedere l'argomento di ListViewGroup riferimento sulla panoramica.

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

Si applica a