ListViewGroup Construtores

Definição

Inicializa uma nova instância da ListViewGroup classe.

Sobrecargas

Name Description
ListViewGroup()

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

ListViewGroup(String)

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

ListViewGroup(String, String)

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

ListViewGroup(String, HorizontalAlignment)

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

ListViewGroup()

Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs

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

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

Aplica-se a

ListViewGroup(String)

Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs

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

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 mostrar para o cabeçalho do grupo.

Aplica-se a

ListViewGroup(String, String)

Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs

Inicializa uma nova instância da ListViewGroup classe usando os valores especificados para inicializar as Name propriedades 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 Name propriedade.

headerText
String

O valor inicial da Header propriedade.

Aplica-se a

ListViewGroup(String, HorizontalAlignment)

Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs
Origem:
ListViewGroup.cs

Inicializa uma nova instância da ListViewGroup classe usando o texto do cabeçalho especificado e o alinhamento do 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 mostrar para o cabeçalho do grupo.

headerAlignment
HorizontalAlignment

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

Exemplos

O exemplo de código seguinte demonstra como o ListViewGroup construtor pode ser usado numa aplicação que organiza ListView itens por valor de subitem na vista de detalhes. Esta forma de agrupamento é semelhante à utilizada no Windows Explorer. No exemplo, os grupos são criados dinamicamente. Para cada coluna de subitem, é criado um grupo para cada valor único de subitem. Para a coluna do item-pai, é criado um grupo para cada letra inicial única. Os grupos criados para cada coluna são armazenados numa tabela de hash juntamente com o texto do subitem ou a letra inicial. Quando um cabeçalho de coluna é clicado, este valor de texto é usado para associar itens a grupos para a coluna apropriada.

Para 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