Use ListView groups in C#

ListView groups

Many developers don’t realize that the ListView control can display items in groups. You can create ListView groups at either design or run time. Then you can add items to the groups. If you add an item without specifying a group, it is displayed in a special “Default” group.

This program uses the following code to create two groups at run time.

// Add some groups to the ListView.
ListViewGroup csharp_group = new ListViewGroup("C# Books");
ListViewGroup vb_group = new ListViewGroup("Visual Basic Books");

It then adds several items to the groups. It also adds one item without a group. The following code shows how the program adds an item to the “C# Books” group.

// C# Books.
lvwBooks.Items.Add(new ListViewItem(new string[]
    {   "C# 5.0 Programmer's Reference",
        "" +
        "960", "2014"},

The program uses similar code to add the other items.

Download the example to see additional details, such as how the program displays different ListView views (large icon, small icon, detail, and so forth).

Download Example   Follow me on Twitter   RSS feed

This entry was posted in controls, user interface and tagged , , , , , , , , , , , , , . Bookmark the permalink.

5 Responses to Use ListView groups in C#

  1. Pingback: Use ListView data to generate HTML TABLE code in C# -

  2. oghenez says:


    How can i archive this look with grouped listview


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.