Use groups in a ListView control in C#

Many developers don't know that the ListView control can display items in groups.

To use groups, create them at either design or run time. Then add the 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 general_group = new ListViewGroup("General");
ListViewGroup vb_group = new ListViewGroup("Visual Basic Books");
lvwBooks.Groups.Add(general_group);
lvwBooks.Groups.Add(vb_group);

It then adds items to the groups and adds one without a group. The following code shows how the program adds an item to the "General" group.

// General.
lvwBooks.Items.Add(new ListViewItem(new string[]
{ "Beginning Database Design Solutions",
"http://www.vb-helper.com/db_design.htm",
"978-0-470-38549-4",
"552", "2008"},
general_group));

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments

Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.