Share via


ListViewGroup Construtores

Definição

Inicializa uma nova instância da classe ListViewGroup.

Sobrecargas

ListViewGroup()

Inicializa uma nova instância da classe ListViewGroup usando o texto de cabeçalho padrão de "ListViewGroup" e alinhamento de cabeçalho à esquerda padrão.

ListViewGroup(String)

Inicializa uma nova instância da classe ListViewGroup usando o valor especificado para inicializar a propriedade Header e usando o alinhamento de cabeçalho à esquerda padrão.

ListViewGroup(String, String)

Inicializa uma nova instância da classe ListViewGroup usando os valors especificados para inicializar as propriedades Name e Header.

ListViewGroup(String, HorizontalAlignment)

Inicializa uma nova instância da classe ListViewGroup usando o texto de cabeçalho especificado e o alinhamento de cabeçalho especificado.

ListViewGroup()

Inicializa uma nova instância da classe ListViewGroup usando o texto de cabeçalho padrão de "ListViewGroup" e alinhamento de cabeçalho à esquerda padrão.

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

Aplica-se a

ListViewGroup(String)

Inicializa uma nova instância da classe ListViewGroup usando o valor especificado para inicializar a propriedade Header e usando o alinhamento de cabeçalho à esquerda padrão.

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)

Parâmetros

header
String

O texto a ser exibido para o cabeçalho de grupo.

Aplica-se a

ListViewGroup(String, String)

Inicializa uma nova instância da classe ListViewGroup usando os valors especificados para inicializar as propriedades Name e Header.

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)

Parâmetros

key
String

O valor inicial da propriedade Name.

headerText
String

O valor inicial da propriedade Header.

Aplica-se a

ListViewGroup(String, HorizontalAlignment)

Inicializa uma nova instância da classe ListViewGroup usando o texto de cabeçalho especificado e o alinhamento de cabeçalho especificado.

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)

Parâmetros

header
String

O texto a ser exibido para o cabeçalho de grupo.

headerAlignment
HorizontalAlignment

Um dos valores HorizontalAlignment que especifica o alinhamento do texto do cabeçalho.

Exemplos

O exemplo de código a seguir demonstra como o ListViewGroup construtor pode ser usado em um aplicativo que organiza ListView itens por valor subitem na exibição de detalhes. Essa forma de agrupamento é semelhante ao agrupamento usado no Gerenciador de Windows. No exemplo, os grupos são criados dinamicamente. Para cada coluna subitem, um grupo é criado para cada valor de subitem exclusivo. Para a coluna de item pai, um grupo é criado para cada letra inicial exclusiva. Os grupos criados para cada coluna são armazenados em uma tabela de hash junto com o texto subitem ou a letra inicial. Quando um cabeçalho de coluna é clicado, esse valor de texto é usado para corresponder itens a grupos para a coluna apropriada.

Para obter o exemplo completo, consulte o ListViewGroup tópico de referência de visão geral.

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

Aplica-se a