ListViewGroup ListViewGroup ListViewGroup ListViewGroup Class

정의

ListView 컨트롤에 표시되는 항목의 그룹을 나타냅니다.Represents a group of items displayed within a ListView control.

public ref class ListViewGroup sealed : System::Runtime::Serialization::ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ListViewGroupConverter))]
[System.Serializable]
public sealed class ListViewGroup : System.Runtime.Serialization.ISerializable
type ListViewGroup = class
    interface ISerializable
Public NotInheritable Class ListViewGroup
Implements ISerializable
상속
ListViewGroupListViewGroupListViewGroupListViewGroup
특성
구현

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 ListView 그룹화 세부 정보 뷰에서 하위 항목 값으로 항목을 구성 하는 기능입니다.The following code example demonstrates how to use the ListView grouping feature to organize items by subitem value in the details view. 이러한 형태의 그룹화 Windows 탐색기에서 사용 되는 그룹화 하는 것과 비슷합니다.This form of grouping is similar to the grouping used in Windows Explorer. 예제에서는 그룹을 동적으로 생성 됩니다.In the example, the groups are created dynamically. 각 하위 항목 열에 대 한 각 하위 항목 고유 값에 대해 하나의 그룹이 만들어집니다.For each subitem column, one group is created for each unique subitem value. 부모 항목 열에 대 한 각 고유 첫 문자에 대 한 하나의 그룹이 만들어집니다.For the parent item column, one group is created for each unique initial letter. 열 머리글을 클릭 하면 해당 열에 대해 만든 그룹에는 항목을 정렬 합니다.Clicking the header of a column sorts the items into the groups created for that column. 동일한 열 머리글을 다시 클릭 하면 그룹의 순서를 반대로 바꿉니다.Clicking the same column header again reverses the order of the groups.

#using <mscorlib.dll>
#using <System.Drawing.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Collections; 
using namespace System::Windows::Forms;

public ref class ListViewGroupsExample : public Form
{
private:
   ListView^ myListView;
   bool isRunningXPOrLater;

   // Declare a Hashtable array in which to store the groups.
   array<Hashtable^>^ groupTables;

   // Declare a variable to store the current grouping column.
   int groupColumn;

public:
   ListViewGroupsExample()
   {
      groupColumn = 0;
      // Initialize myListView.
      myListView = gcnew ListView();
      myListView->Dock = DockStyle::Fill;
      myListView->View = View::Details;
      myListView->Sorting = SortOrder::Ascending;

      // Create and initialize column headers for myListView.
      ColumnHeader^ columnHeader0 = gcnew ColumnHeader();
      columnHeader0->Text = "Title";
      columnHeader0->Width = -1;
      ColumnHeader^ columnHeader1 = gcnew ColumnHeader();
      columnHeader1->Text = "Author";
      columnHeader1->Width = -1;
      ColumnHeader^ columnHeader2 = gcnew ColumnHeader();
      columnHeader2->Text = "Year";
      columnHeader2->Width = -1;

      // Add the column headers to myListView.

      array<ColumnHeader^>^ temp0 = {columnHeader0, columnHeader1, columnHeader2};
      myListView->Columns->AddRange(temp0);

      // Add a handler for the ColumnClick event.
      myListView->ColumnClick += 
         gcnew ColumnClickEventHandler(this, &ListViewGroupsExample::myListView_ColumnClick);

      // Create items and add them to myListView.

      array<String^>^ temp1 = {"Programming Windows", "Petzold, Charles", "1998"};
      ListViewItem^ item0 = gcnew ListViewItem( temp1 );

      array<String^>^ temp2 = {"Code: The Hidden Language of Computer Hardware and Software",
         "Petzold, Charles", "2000"};
      ListViewItem^ item1 = gcnew ListViewItem( temp2 );

      array<String^>^ temp3 = {"Programming Windows with C#", "Petzold, Charles", "2001"};
      ListViewItem^ item2 = gcnew ListViewItem( temp3 );

      array<String^>^ temp4 = {"Coding Techniques for Microsoft Visual Basic .NET",
         "Connell, John", "2001"};
      ListViewItem^ item3 = gcnew ListViewItem( temp4 );

      array<String^>^ temp5 = {"C# for Java Developers", "Jones, Allen & Freeman, Adam",
         "2002"};
      ListViewItem^ item4 = gcnew ListViewItem( temp5 );

      array<String^>^ temp6 = {"Microsoft .NET XML Web Services Step by Step",
         "Jones, Allen & Freeman, Adam", "2002"};
      ListViewItem^ item5 = gcnew ListViewItem( temp6 );

      array<ListViewItem^>^ temp7 = {item0, item1, item2, item3, item4, item5};
      myListView->Items->AddRange( temp7 );

      // Determine whether Windows XP or a later 
      // operating system is present.
      isRunningXPOrLater = false;

      if (System::Environment::OSVersion->Version->Major > 5 ||
         ( System::Environment::OSVersion->Version->Major == 5 &&
         System::Environment::OSVersion->Version->Minor >= 1) )
      {
         isRunningXPOrLater = true;
      }

      if (isRunningXPOrLater)
      {
         // Create the groupsTable array and populate it with one 
         // hash table for each column.
         groupTables = gcnew array<Hashtable^>(myListView->Columns->Count);
         for (int column = 0; column < myListView->Columns->Count; column++)
         {
            // Create a hash table containing all the groups 
            // needed for a single column.
            groupTables[column] = CreateGroupsTable(column);
         }

         // Start with the groups created for the Title column.
         SetGroups(0);
      }

      // Initialize the form.
      this->Controls->Add(myListView);
      this->Size = System::Drawing::Size(550, 330);
      this->Text = "ListView Groups Example";
   }

   // Groups the items using the groups created for the clicked 
   // column.
private:
   void myListView_ColumnClick(
      Object^ /*sender*/, ColumnClickEventArgs^ e)
   {
      // Set the sort order to ascending when changing
      // column groups; otherwise, reverse the sort order.
      if ( myListView->Sorting == SortOrder::Descending || 
         ( isRunningXPOrLater && (e->Column != groupColumn) ) )
      {
         myListView->Sorting = SortOrder::Ascending;
      }
      else 
      {
         myListView->Sorting = SortOrder::Descending;
      }
      groupColumn = e->Column;

      // Set the groups to those created for the clicked column.
      if (isRunningXPOrLater)
      {
         SetGroups(e->Column);
      }
   }

   // Sets myListView to the groups created for the specified column.
private:
   void SetGroups(int column)
   {
      // Remove the current groups.
      myListView->Groups->Clear();

      // Retrieve the hash table corresponding to the column.
      Hashtable^ groups = dynamic_cast<Hashtable^>(groupTables[column]);

      // Copy the groups for the column to an array.
      array<ListViewGroup^>^ groupsArray = gcnew array<ListViewGroup^>(groups->Count);
      groups->Values->CopyTo(groupsArray, 0);

      // Sort the groups and add them to myListView.
      Array::Sort(groupsArray, gcnew ListViewGroupSorter(myListView->Sorting));
      myListView->Groups->AddRange(groupsArray);

      // Iterate through the items in myListView, assigning each 
      // one to the appropriate group.
      IEnumerator^ myEnum = myListView->Items->GetEnumerator();
      while (myEnum->MoveNext())
      {
         ListViewItem^ item = safe_cast<ListViewItem^>(myEnum->Current);
         // Retrieve the subitem text corresponding to the column.
         String^ subItemText = item->SubItems[column]->Text;

         // For the Title column, use only the first letter.
         if (column == 0) 
         {
            subItemText = subItemText->Substring(0, 1);
         }

         // Assign the item to the matching group.
         item->Group = dynamic_cast<ListViewGroup^>(groups[subItemText]);
      }
   }

   // 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;
   }

   // Sorts ListViewGroup objects by header value.
   ref class ListViewGroupSorter : public IComparer
   {
   private:
      SortOrder order;

      // Stores the sort order.
   public:
      ListViewGroupSorter(SortOrder theOrder) 
      { 
         order = theOrder;
      }

      // Compares the groups by header value, using the saved sort
      // order to return the correct value.
      virtual int Compare(Object^ x, Object^ y)
      {
         int result = String::Compare(
            (dynamic_cast<ListViewGroup^>(x))->Header,
            (dynamic_cast<ListViewGroup^>(y))->Header
            );
         if (order == SortOrder::Ascending)
         {
            return result;
         }
         else 
         {
            return -result;
         }
      }
   };
};

[STAThread]
int main() 
{
   Application::EnableVisualStyles();
   Application::Run(gcnew ListViewGroupsExample());
}
using System;
using System.Collections; 
using System.Windows.Forms;

public class ListViewGroupsExample : Form
{
    private ListView myListView;

    // Determine whether Windows XP or a later
    // operating system is present.
    private bool isRunningXPOrLater = 
        OSFeature.Feature.IsPresent(OSFeature.Themes);

    // Declare a Hashtable array in which to store the groups.
    private Hashtable[] groupTables;

    // Declare a variable to store the current grouping column.
    int groupColumn = 0;

    public ListViewGroupsExample()
    {
        // Initialize myListView.
        myListView = new ListView();
        myListView.Dock = DockStyle.Fill;
        myListView.View = View.Details;
        myListView.Sorting = SortOrder.Ascending;

        // Create and initialize column headers for myListView.
        ColumnHeader columnHeader0 = new ColumnHeader();
        columnHeader0.Text = "Title";
        columnHeader0.Width = -1;
        ColumnHeader columnHeader1 = new ColumnHeader();
        columnHeader1.Text = "Author";
        columnHeader1.Width = -1;
        ColumnHeader columnHeader2 = new ColumnHeader();
        columnHeader2.Text = "Year";
        columnHeader2.Width = -1;

        // Add the column headers to myListView.
        myListView.Columns.AddRange(new ColumnHeader[] 
            {columnHeader0, columnHeader1, columnHeader2});

        // Add a handler for the ColumnClick event.
        myListView.ColumnClick += 
            new ColumnClickEventHandler(myListView_ColumnClick);

        // Create items and add them to myListView.
        ListViewItem item0 = new ListViewItem( new string[] 
            {"Programming Windows", 
            "Petzold, Charles", 
            "1998"} );
        ListViewItem item1 = new ListViewItem( new string[] 
            {"Code: The Hidden Language of Computer Hardware and Software", 
            "Petzold, Charles", 
            "2000"} );
        ListViewItem item2 = new ListViewItem( new string[] 
            {"Programming Windows with C#", 
            "Petzold, Charles", 
            "2001"} );
        ListViewItem item3 = new ListViewItem( new string[] 
            {"Coding Techniques for Microsoft Visual Basic .NET", 
            "Connell, John", 
            "2001"} );
        ListViewItem item4 = new ListViewItem( new string[] 
            {"C# for Java Developers", 
            "Jones, Allen & Freeman, Adam", 
            "2002"} );
        ListViewItem item5 = new ListViewItem( new string[] 
            {"Microsoft .NET XML Web Services Step by Step", 
            "Jones, Allen & Freeman, Adam", 
            "2002"} );
        myListView.Items.AddRange(
            new ListViewItem[] {item0, item1, item2, item3, item4, item5});

        if (isRunningXPOrLater)
        {
            // Create the groupsTable array and populate it with one 
            // hash table for each column.
            groupTables = new Hashtable[myListView.Columns.Count];
            for (int column = 0; column < myListView.Columns.Count; column++)
            {
                // Create a hash table containing all the groups 
                // needed for a single column.
                groupTables[column] = CreateGroupsTable(column);
            }

            // Start with the groups created for the Title column.
            SetGroups(0);
        }

        // Initialize the form.
        this.Controls.Add(myListView);
        this.Size = new System.Drawing.Size(550, 330);
        this.Text = "ListView Groups Example";
    }

    [STAThread]
    static void Main() 
    {
        Application.EnableVisualStyles();
        Application.Run(new ListViewGroupsExample());
    }

    // Groups the items using the groups created for the clicked 
    // column.
    private void myListView_ColumnClick(
        object sender, ColumnClickEventArgs e)
    {
        // Set the sort order to ascending when changing
        // column groups; otherwise, reverse the sort order.
        if ( myListView.Sorting == SortOrder.Descending || 
            ( isRunningXPOrLater && (e.Column != groupColumn) ) )
        {
            myListView.Sorting = SortOrder.Ascending;
        }
        else 
        {
            myListView.Sorting = SortOrder.Descending;
        }
        groupColumn = e.Column;

        // Set the groups to those created for the clicked column.
        if (isRunningXPOrLater)
        {
            SetGroups(e.Column);
        }
    }

    // Sets myListView to the groups created for the specified column.
    private void SetGroups(int column)
    {
        // Remove the current groups.
        myListView.Groups.Clear();

        // Retrieve the hash table corresponding to the column.
        Hashtable groups = (Hashtable)groupTables[column];

        // Copy the groups for the column to an array.
        ListViewGroup[] groupsArray = new ListViewGroup[groups.Count];
        groups.Values.CopyTo(groupsArray, 0);

        // Sort the groups and add them to myListView.
        Array.Sort(groupsArray, new ListViewGroupSorter(myListView.Sorting));
        myListView.Groups.AddRange(groupsArray);

        // Iterate through the items in myListView, assigning each 
        // one to the appropriate group.
        foreach (ListViewItem item in myListView.Items)
        {
            // Retrieve the subitem text corresponding to the column.
            string subItemText = item.SubItems[column].Text;

            // For the Title column, use only the first letter.
            if (column == 0) 
            {
                subItemText = subItemText.Substring(0, 1);
            }

            // Assign the item to the matching group.
            item.Group = (ListViewGroup)groups[subItemText];
        }
    }

    // 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;
    }

    // Sorts ListViewGroup objects by header value.
    private class ListViewGroupSorter : IComparer
    {
        private SortOrder order;

        // Stores the sort order.
        public ListViewGroupSorter(SortOrder theOrder) 
        { 
            order = theOrder;
        }

        // Compares the groups by header value, using the saved sort
        // order to return the correct value.
        public int Compare(object x, object y)
        {
            int result = String.Compare(
                ((ListViewGroup)x).Header,
                ((ListViewGroup)y).Header
            );
            if (order == SortOrder.Ascending)
            {
                return result;
            }
            else 
            {
                return -result;
            }
        }
    }

}
Imports System.Collections
Imports System.Windows.Forms

Public Class ListViewGroupsExample
    Inherits Form

    Private myListView As ListView

    ' Determine whether Windows XP or a later
    ' operating system is present.
    Private isRunningXPOrLater As Boolean = _
        OSFeature.Feature.IsPresent(OSFeature.Themes)
    
    ' Declare a Hashtable array in which to store the groups.
    Private groupTables() As Hashtable
    
    ' Declare a variable to store the current grouping column.
    Private groupColumn As Integer = 0
    
    Public Sub New()
        ' Initialize myListView.
        myListView = New ListView()
        myListView.Dock = DockStyle.Fill
        myListView.View = View.Details
        myListView.Sorting = SortOrder.Ascending
        
        ' Create and initialize column headers for myListView.
        Dim columnHeader0 As New ColumnHeader()
        columnHeader0.Text = "Title"
        columnHeader0.Width = -1
        Dim columnHeader1 As New ColumnHeader()
        columnHeader1.Text = "Author"
        columnHeader1.Width = -1
        Dim columnHeader2 As New ColumnHeader()
        columnHeader2.Text = "Year"
        columnHeader2.Width = -1
        
        ' Add the column headers to myListView.
        myListView.Columns.AddRange( New ColumnHeader() _
            {columnHeader0, columnHeader1, columnHeader2} )
        
        ' Add a handler for the ColumnClick event.
        AddHandler myListView.ColumnClick, AddressOf myListView_ColumnClick
        
        ' Create items and add them to myListView.
        Dim item0 As New ListViewItem( New String() _
            {"Programming Windows", _
            "Petzold, Charles", _
            "1998"} )
        Dim item1 As New ListViewItem( New String() _
            {"Code: The Hidden Language of Computer Hardware and Software", _
            "Petzold, Charles", _
            "2000"} )
        Dim item2 As New ListViewItem( New String() _
            {"Programming Windows with C#", _
            "Petzold, Charles", _
            "2001"} )
        Dim item3 As New ListViewItem( New String() _
            {"Coding Techniques for Microsoft Visual Basic .NET", _
            "Connell, John", _
            "2001"} )
        Dim item4 As New ListViewItem( New String() _
            {"C# for Java Developers", _
            "Jones, Allen / Freeman, Adam", _
            "2002"} )
        Dim item5 As New ListViewItem( New String() _
            {"Microsoft .NET XML Web Services Step by Step", _
            "Jones, Allen / Freeman, Adam", _
            "2002"} )
        myListView.Items.AddRange( _
            New ListViewItem() {item0, item1, item2, item3, item4, item5})
        
        If isRunningXPOrLater
            ' Create the groupsTable array and populate it with one 
            ' hash table for each column.
            groupTables = New Hashtable(myListView.Columns.Count) {}
            Dim column As Integer
            For column = 0 To myListView.Columns.Count - 1
                ' Create a hash table containing all the groups 
                ' needed for a single column.
                groupTables(column) = CreateGroupsTable(column)
            Next column
            
            ' Start with the groups created for the Title column.
            SetGroups(0)
        End If
        
        ' Initialize the form.
        Me.Controls.Add(myListView)
        Me.Size = New System.Drawing.Size(550, 330)
        Me.Text = "ListView Groups Example"
    End Sub
    
    <STAThread()> _
    Shared Sub Main()
        Application.EnableVisualStyles()
        Application.Run(New ListViewGroupsExample())
    End Sub
    
    ' Groups the items using the groups created for the clicked 
    ' column.
    Private Sub myListView_ColumnClick( _
        sender As Object, e As ColumnClickEventArgs)

        ' Set the sort order to ascending when changing
        ' column groups; otherwise, reverse the sort order.
        If myListView.Sorting = SortOrder.Descending OrElse _
            isRunningXPOrLater And e.Column <> groupColumn Then
            myListView.Sorting = SortOrder.Ascending
        Else
            myListView.Sorting = SortOrder.Descending
        End If
        groupColumn = e.Column
        
        ' Set the groups to those created for the clicked column.
        If isRunningXPOrLater Then
            SetGroups(e.Column)
        End If
    End Sub
    
    ' Sets myListView to the groups created for the specified column.
    Private Sub SetGroups(column As Integer)
        ' Remove the current groups.
        myListView.Groups.Clear()
        
        ' Retrieve the hash table corresponding to the column.
        Dim groups As Hashtable = CType(groupTables(column), Hashtable)
        
        ' Copy the groups for the column to an array.
        Dim groupsArray(groups.Count - 1) As ListViewGroup
        groups.Values.CopyTo(groupsArray, 0)
        
        ' Sort the groups and add them to myListView.
        Array.Sort(groupsArray, New ListViewGroupSorter(myListView.Sorting))
        myListView.Groups.AddRange(groupsArray)
        
        ' Iterate through the items in myListView, assigning each 
        ' one to the appropriate group.
        Dim item As ListViewItem
        For Each item In myListView.Items
            ' Retrieve the subitem text corresponding to the column.
            Dim subItemText As String = item.SubItems(column).Text
            
            ' For the Title column, use only the first letter.
            If column = 0 Then
                subItemText = subItemText.Substring(0, 1)
            End If 

            ' Assign the item to the matching group.
            item.Group = CType(groups(subItemText), ListViewGroup)
        Next item
    End Sub

    ' 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

    ' Sorts ListViewGroup objects by header value.
    Private Class ListViewGroupSorter
        Implements IComparer 
        
        Private order As SortOrder
        
        ' Stores the sort order.
        Public Sub New(theOrder As SortOrder)
            order = theOrder
        End Sub
        
        ' Compares the groups by header value, using the saved sort
        ' order to return the correct value.
        Public Function Compare(x As Object, y As Object) As Integer _
            Implements IComparer.Compare
            Dim result As Integer = String.Compare( _
                CType(x, ListViewGroup).Header, _
                CType(y, ListViewGroup).Header )
            If order = SortOrder.Ascending Then
                Return result
            Else
                Return -result
            End If
        End Function 'Compare
    End Class 'ListViewGroupSorter 

End Class 'ListViewGroupsExample

설명

합니다 ListView 그룹화 기능을 사용 하면 논리적으로 관련 된 시각적 그룹을 만들 수 있습니다 ListView 항목입니다.The ListView grouping feature lets you create visual groups of logically related ListView items. 각 그룹 뒤에 가로 줄 텍스트를 기반으로 헤더 및 해당 그룹에 할당 된 항목으로 구성 됩니다.Each group consists of a text-based header followed by a horizontal line and the items assigned to that group. 왼쪽, 오른쪽 또는 가운데 컨트롤의 머리글 텍스트를 맞출 수 있습니다.You can align the header text to the left, right, or center of the control. 에 할당 된 모든 그룹을 ListView 컨트롤이 표시 될 때마다 합니다 ListView.View 속성 이외의 다른 값으로 설정 됩니다 View.List합니다.Any groups assigned to a ListView control appear whenever the ListView.View property is set to a value other than View.List.

ListView 그룹 도움말 사용자에 게 유용한 범주에 항목을 구분 하 여 찾고 있는 항목을 찾습니다.ListView groups help your users find the items they are looking for by separating the items into useful categories. 필요한 모든 범주를 만들 수 있습니다.You can create whatever categories you need. 항목을 그룹화 하는 일반적인 방법 중 하나는 방식으로 정렬 됩니다.One typical way to group the items is by the way they are sorted. 예를 들어, 형식 또는 세부 정보 뷰에서 열 머리글을 클릭 하 여 목록을 정렬 한 경우 날짜와 같은 하위 항목 또는 사전순으로 정렬 되 었 항목 이름의 첫 글자를 기준 항목을 그룹화 할 수 있습니다.For example, you can group the items by the initial letter of the item name when they are sorted alphabetically, or by subitems such as type or date when the list is sorted by clicking a column header in the details view. Windows 탐색기에서이 유형의 그룹화를 사용 합니다.Windows Explorer uses this type of grouping.

그룹화 기능을 사용 하려면 하나 이상의 추가 ListViewGroup 개체를 ListView.Groups 의 컬렉션을 ListView 컨트롤입니다.To use the grouping feature, add one or more ListViewGroup objects to the ListView.Groups collection of a ListView control. 그룹 머리글의 텍스트와 머리글 맞춤을 설정 합니다 ListViewGroup 생성자를 설정 또는 사용 하 여는 HeaderHeaderAlignment 속성.Set the group header text and header alignment in the ListViewGroup constructor, or set them using the Header and HeaderAlignment properties.

그룹을 지정 하 여 항목 그룹에 할당할 수 있습니다는 ListViewItem 설정 하 여 생성자를 ListViewItem.Group 속성 또는 직접 항목을 추가 하 여는 Items 그룹의 컬렉션입니다.You can assign an item to a group by specifying the group in the ListViewItem constructor, by setting the ListViewItem.Group property, or by directly adding the item to the Items collection of a group. 모든 항목 표시 되기 전에 그룹에 할당 되어야 합니다.All items should be assigned to groups before they are displayed. 머리글 레이블에 있는 기본 그룹의 그룹에 할당 되지 않은 모든 항목도 표시 되지 것입니다 "DefaultGroup{0}"입니다.Any items that are not assigned to a group will appear in the default group, which has the header label "DefaultGroup{0}". 기본 그룹에 포함 되어 있지는 ListView.Groups 컬렉션을 변경할 수 없습니다.The default group is not contained in the ListView.Groups collection, and cannot be altered. 모든 항목이 있는 그룹에 올바르게 추가 되었는지 확인 하는 디버깅에 주로 유용 합니다.It is primarily useful in debugging to ensure that all items have been properly added to groups.

한 번에 하나의 그룹에서 항목을 수만 있습니다.An item can only be in one group at a time. 설정 하 여 항목이 속해 있는 그룹을 변경할 수 있습니다는 ListViewItem.Group 런타임에 또는 추가 하 여 속성을 Items 이전 그룹에서 자동으로 제거 하는 다른 그룹의 컬렉션입니다.You can change the group to which an item belongs by setting the ListViewItem.Group property at run time or by adding it to the Items collection of another group, which automatically removes it from the previous group.

참고

그룹을 사용 하는 경우 삽입 표시 기능은 비활성화 됩니다.The insertion mark feature is disabled when using groups. 삽입 표시 기능은 끌어서 놓기 위치에서 사용 하는 동안 그룹화 기능은 그룹 멤버 자격 항목을 정렬 되므로이 ListView 이미 해당 항목을 정렬 되지 않은 컨트롤입니다.This is because the grouping feature orders items by group membership, while the insertion mark feature is used with drag-and-drop repositioning in a ListView control that does not already order its items.

참고

ListView 애플리케이션에서 호출 하는 경우 그룹은 Windows XP 및 Windows Server 2003 제품군 에서만 사용할 수는 Application.EnableVisualStyles 메서드.ListView groups are available only on Windows XP and the Windows Server 2003 family when your application calls the Application.EnableVisualStyles method. 이전 버전의 운영 체제 그룹 관련 모든 코드가 무시 되 고 그룹 표시 되지 않습니다.On earlier operating systems, any code relating to groups will be ignored and the groups will not appear. 결과적으로 그룹화 기능을 사용 하는 코드가 제대로 작동 하지 않을 수 있습니다.As a result, any code that depends on the grouping feature might not work correctly. 그룹화 기능을 사용할 수 있는지 여부를 확인 하는 테스트를 포함할 수도 있으며 사용할 수 없을 때 대체 기능을 제공할 수 있습니다.You might want to include a test that determines whether the grouping feature is available, and provide alternate functionality when it is unavailable. 예를 들어, 다음 그룹으로 정렬 하는 것을 지원 하지 않는 운영 체제에서 실행 하는 경우 대체 정렬을 제공 하는 것이 좋습니다.For example, you might want to provide alternate sorting when running on operating systems that do not support sorting by group.

삽입 표시 기능은 운영 체제 테마 기능을 제공 하는 라이브러리에서 제공 됩니다.The insertion mark feature is provided by the same library that provides the operating system themes feature. 이 라이브러리의 가용성을 확인 하려면 호출을 FeatureSupport.IsPresent(Object) 메서드 오버 로드 하 고 전달 합니다 OSFeature.Themes 값입니다.To check for the availability of this library, call the FeatureSupport.IsPresent(Object) method overload and pass in the OSFeature.Themes value.

생성자

ListViewGroup() ListViewGroup() ListViewGroup() ListViewGroup()

"ListViewGroup"의 기본 머리글 텍스트 및 기본 왼쪽 머리글 맞춤을 사용하여 ListViewGroup 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ListViewGroup class using the default header text of "ListViewGroup" and the default left header alignment.

ListViewGroup(String) ListViewGroup(String) ListViewGroup(String) ListViewGroup(String)

ListViewGroup 속성을 초기화하는 지정된 값과 기본 왼쪽 머리글 맞춤을 사용하여 Header 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ListViewGroup class using the specified value to initialize the Header property and using the default left header alignment.

ListViewGroup(String, HorizontalAlignment) ListViewGroup(String, HorizontalAlignment) ListViewGroup(String, HorizontalAlignment) ListViewGroup(String, HorizontalAlignment)

지정된 머리글 텍스트 및 지정된 머리글 맞춤을 사용하여 ListViewGroup 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ListViewGroup class using the specified header text and the specified header alignment.

ListViewGroup(String, String) ListViewGroup(String, String) ListViewGroup(String, String) ListViewGroup(String, String)

ListViewGroupName 속성을 초기화하기 위해 지정된 값을 사용하여 Header 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ListViewGroup class using the specified values to initialize the Name and Header properties.

속성

Header Header Header Header

그룹의 머리글 텍스트를 가져오거나 설정합니다.Gets or sets the header text for the group.

HeaderAlignment HeaderAlignment HeaderAlignment HeaderAlignment

그룹 머리글 텍스트의 맞춤을 가져오거나 설정합니다.Gets or sets the alignment of the group header text.

Items Items Items Items

이 그룹과 연결된 모든 항목이 들어 있는 컬렉션을 가져옵니다.Gets a collection containing all items associated with this group.

ListView ListView ListView ListView

이 그룹이 들어 있는 ListView 컨트롤을 가져옵니다.Gets the ListView control that contains this group.

Name Name Name Name

그룹의 이름을 가져오거나 설정합니다.Gets or sets the name of the group.

Tag Tag Tag Tag

그룹에 대한 데이터가 들어 있는 개체를 가져오거나 설정합니다.Gets or sets the object that contains data about the group.

메서드

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

명시적 인터페이스 구현

ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

대상 개체를 serialize하는 데 필요한 데이터로 SerializationInfo를 채웁니다.Populates a SerializationInfo with the data needed to serialize the target object.

적용 대상

추가 정보