ListViewGroup Class

 

Represents a group of items displayed within a ListView control.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

System.Object
  System.Windows.Forms.ListViewGroup

[<Sealed>]
[<SerializableAttribute>]
type ListViewGroup = 
    class
        interface ISerializable
    end

NameDescription
System_CAPS_pubmethodListViewGroup()

Initializes a new instance of the ListViewGroup class using the default header text of "ListViewGroup" and the default left header alignment.

System_CAPS_pubmethodListViewGroup(String)

Initializes a new instance of the ListViewGroup class using the specified value to initialize the Header property and using the default left header alignment.

System_CAPS_pubmethodListViewGroup(String, HorizontalAlignment)

Initializes a new instance of the ListViewGroup class using the specified header text and the specified header alignment.

System_CAPS_pubmethodListViewGroup(String, String)

Initializes a new instance of the ListViewGroup class using the specified values to initialize the Name and Header properties.

NameDescription
System_CAPS_pubpropertyHeader

Gets or sets the header text for the group.

System_CAPS_pubpropertyHeaderAlignment

Gets or sets the alignment of the group header text.

System_CAPS_pubpropertyItems

Gets a collection containing all items associated with this group.

System_CAPS_pubpropertyListView

Gets the ListView control that contains this group.

System_CAPS_pubpropertyName

Gets or sets the name of the group.

System_CAPS_pubpropertyTag

Gets or sets the object that contains data about the group.

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Overrides Object.ToString().)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodISerializable.GetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo with the data needed to serialize the target object.

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. Any groups assigned to a ListView control appear whenever the ListView.View property is set to a value other than View.List.

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 Explorer uses this type of grouping.

To use the grouping feature, add one or more ListViewGroup objects to the ListView.Groups collection of a ListView control. Set the group header text and header alignment in the ListViewGroup constructor, or set them using the Header and HeaderAlignment properties.

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. Any items that are not assigned to a group will appear in the default group, which has the header label "DefaultGroup{0}". 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. 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.

System_CAPS_noteNote

The insertion mark feature is disabled when using groups. 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.

System_CAPS_noteNote

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. To check for the availability of this library, call the FeatureSupport.IsPresent(Object) method overload and pass in the OSFeature.Themes value.

The following code example demonstrates how to use the ListView grouping feature to organize items by subitem value in the details view. 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.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: