[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: 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"); lvwBooks.Groups.Add(csharp_group); lvwBooks.Groups.Add(vb_group);

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", "http://www.wrox.com/WileyCDA/WroxTitle/C-5-0-" + "Programmer-s-Reference.productCd-1118847288.html", "978-1-118-84728-2", "960", "2014"}, csharp_group));

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 the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.