ListViewGroup コンストラクター

定義

ListViewGroup クラスの新しいインスタンスを初期化します。

オーバーロード

名前 説明
ListViewGroup()

"ListViewGroup" の既定のヘッダー テキストと既定の左ヘッダー配置を使用して、 ListViewGroup クラスの新しいインスタンスを初期化します。

ListViewGroup(String)

指定した値を使用して ListViewGroup クラスの新しいインスタンスを初期化し、 Header プロパティを初期化し、既定の左ヘッダー配置を使用します。

ListViewGroup(String, String)

指定した値を使用して ListViewGroup クラスの新しいインスタンスを初期化し、 Name プロパティと Header プロパティを初期化します。

ListViewGroup(String, HorizontalAlignment)

指定したヘッダー テキストと指定したヘッダー配置を使用して、 ListViewGroup クラスの新しいインスタンスを初期化します。

ListViewGroup()

ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs

"ListViewGroup" の既定のヘッダー テキストと既定の左ヘッダー配置を使用して、 ListViewGroup クラスの新しいインスタンスを初期化します。

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

適用対象

ListViewGroup(String)

ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs
ソース:
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)

ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs

指定した値を使用して 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)

パラメーター

key
String

Name プロパティの初期値。

headerText
String

Header プロパティの初期値。

適用対象

ListViewGroup(String, HorizontalAlignment)

ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs
ソース:
ListViewGroup.cs
ソース:
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 値の 1 つ。

次のコード例は、詳細ビューのサブ項目値によってListViewGroup項目を整理するアプリケーションで、ListView コンストラクターを使用する方法を示しています。 この形式のグループ化は、Windows エクスプローラーで使用されるグループ化に似ています。 この例では、グループは動的に作成されます。 サブ項目列ごとに、一意のサブ項目値ごとに 1 つのグループが作成されます。 親項目列の場合、一意の最初の文字ごとに 1 つのグループが作成されます。 各列に対して作成されたグループは、サブ項目テキストまたは最初の文字と共にハッシュ テーブルに格納されます。 列ヘッダーをクリックすると、このテキスト値は、項目を適切な列のグループと照合するために使用されます。

完全な例については、 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

適用対象