How to: Group Items in a Windows Forms ListView Control Using the Designer

The grouping feature of the ListView control enables you to display related sets of items in groups. These groups are separated on the screen by horizontal group headers that contain the group titles. You can use ListView groups to make navigating large lists easier by grouping items alphabetically, by date, or by any other logical grouping. The following image shows some grouped items:

Numbers separated into odd and even groups.

The following procedure requires a Windows Application project with a form containing a ListView control. For information about setting up such a project, see How to: Create a Windows Forms application project and How to: Add Controls to Windows Forms.

To enable grouping, you must first create one or more ListViewGroup objects either in the designer or programmatically. Once a group has been defined, you can assign items to it.

To add or remove groups in the designer

  1. In the Properties window, click the Ellipsis (The Ellipsis button (...) in the Properties window of Visual Studio.) button next to the Groups property.

    The ListViewGroup Collection Editor appears.

  2. To add a group, click the Add button. You can then set properties of the new group, such as the Header and HeaderAlignment properties. To remove a group, select it and click the Remove button.

To assign items to groups in the designer

  1. In the Properties window, click the Ellipsis (The Ellipsis button (...) in the Properties window of Visual Studio.) button next to the Items property.

    The ListViewItem Collection Editor appears.

  2. To add a new item, click the Add button. You can then set properties of the new item, such as the Text and ImageIndex properties.

  3. Select the Group property and choose a group from the drop-down list.

See also