ListViewGroup コンストラクター

定義

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

オーバーロード

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)

パラメーター

key
String

Name プロパティの初期値。

headerText
String

Header プロパティの初期値。

適用対象

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 値の 1 つ。

次のコード例は、詳細ビューのサブ項目値によって項目を整理ListViewするアプリケーションでコンストラクターを使用する方法ListViewGroupを示しています。 このグループ化の形式は、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

適用対象