ListViewGroup 构造函数

定义

初始化 ListViewGroup 类的新实例。

重载

名称 说明
ListViewGroup()

使用默认标头文本“ListViewGroup”和默认左标题对齐方式初始化类的新实例 ListViewGroup

ListViewGroup(String)

使用指定的值初始化属性并使用默认左标题对齐方式初始化ListViewGroup类的新实例Header

ListViewGroup(String, String)

使用指定的值初始化类的新实例 ListViewGroup ,以初始化 NameHeader 属性。

ListViewGroup(String, HorizontalAlignment)

使用指定的标头文本和指定的标头对齐方式初始化类的新实例 ListViewGroup

ListViewGroup()

Source:
ListViewGroup.cs
Source:
ListViewGroup.cs
Source:
ListViewGroup.cs
Source:
ListViewGroup.cs
Source:
ListViewGroup.cs

使用默认标头文本“ListViewGroup”和默认左标题对齐方式初始化类的新实例 ListViewGroup

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

适用于

ListViewGroup(String)

Source:
ListViewGroup.cs
Source:
ListViewGroup.cs
Source:
ListViewGroup.cs
Source:
ListViewGroup.cs
Source:
ListViewGroup.cs

使用指定的值初始化属性并使用默认左标题对齐方式初始化ListViewGroup类的新实例Header

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)

参数

header
String

要为组标头显示的文本。

适用于

ListViewGroup(String, String)

Source:
ListViewGroup.cs
Source:
ListViewGroup.cs
Source:
ListViewGroup.cs
Source:
ListViewGroup.cs
Source:
ListViewGroup.cs

使用指定的值初始化类的新实例 ListViewGroup ,以初始化 NameHeader 属性。

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)

参数

key
String

属性的初始 Name 值。

headerText
String

属性的初始 Header 值。

适用于

ListViewGroup(String, HorizontalAlignment)

Source:
ListViewGroup.cs
Source:
ListViewGroup.cs
Source:
ListViewGroup.cs
Source:
ListViewGroup.cs
Source:
ListViewGroup.cs

使用指定的标头文本和指定的标头对齐方式初始化类的新实例 ListViewGroup

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)

参数

header
String

要为组标头显示的文本。

headerAlignment
HorizontalAlignment

HorizontalAlignment指定标题文本对齐方式的值之一。

示例

下面的代码示例演示如何 ListViewGroup 在按子项值在详细信息视图中组织 ListView 项的应用程序中使用构造函数。 这种分组形式类似于 Windows 资源管理器中使用的分组。 在此示例中,组是动态创建的。 对于每个子项列,为每个唯一子项值创建一个组。 对于父项列,为每个唯一的初始字母创建一个组。 为每个列创建的组存储在哈希表中,以及子项文本或首字母。 单击列标题时,此文本值用于将项目与相应列的组匹配。

有关完整示例,请参阅 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

适用于