Share via


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.

ListView 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 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.

Note

ListView groups are available only on Windows XP Home Edition, Windows XP Professional, Windows Server 2003 when your application calls the System.Windows.Forms.Application.EnableVisualStyles method. On earlier operating systems, any code relating to groups has no effect and the groups will not appear. For more information, see System.Windows.Forms.ListView.Groups.

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To add or remove groups in the designer

  1. In the Properties window, click the Ellipsis (VisualStudioEllipsesButton screenshot) 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 (VisualStudioEllipsesButton screenshot) 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

Tasks

How to: Add and Remove Items with the Windows Forms ListView Control

Reference

ListView Control Overview (Windows Forms)
ListView
Groups
ListViewGroup

Concepts

Windows XP Features and Windows Forms Controls

Other Resources

ListView Control (Windows Forms)