ListViewGroup 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 ListViewGroup 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| ListViewGroup() |
使用預設的「ListViewGroup」標頭文字及預設左側標頭對齊來初始化該 ListViewGroup 類別的新實例。 |
| ListViewGroup(String) |
使用指定的值初始化ListViewGroup該屬性,並使用預設的左側標頭對齊來初始化該類別的新實例Header。 |
| ListViewGroup(String, String) |
使用指定的值初始化該類別的新實例 ListViewGroup ,以初始化 Name 和 Header 屬性。 |
| ListViewGroup(String, HorizontalAlignment) |
使用指定的標頭文字與標頭對齊初始化該類別的新 ListViewGroup 實例。 |
ListViewGroup()
使用預設的「ListViewGroup」標頭文字及預設左側標頭對齊來初始化該 ListViewGroup 類別的新實例。
public:
ListViewGroup();
public ListViewGroup();
Public Sub New ()
適用於
ListViewGroup(String)
使用指定的值初始化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)
使用指定的值初始化該類別的新實例 ListViewGroup ,以初始化 Name 和 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)
參數
適用於
ListViewGroup(String, HorizontalAlignment)
使用指定的標頭文字與標頭對齊初始化該類別的新 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