Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / MFC
Article

ListView Grouping XP Style

Rate me:
Please Sign up or sign in to vote.
4.64/5 (56 votes)
27 May 2004CPOL1 min read 368.3K   6.8K   195   99
Group ListView items by any column, XP style.

Sample Image - GroupListView.jpg

Introduction

The controls included with Microsoft’s IDE have always been feature rich. However, Microsoft always seems to leave out as many features as they include. The ListView control is no exception to this rule. This project aims at exposing and wrapping a few cool features. First to note is the ability to group items. In Windows Explorer’s View menu, the “Arrange Icon by” menu has a “Show in Groups” option. This allows the ListView to arrange items logically into groups, generally based on file type. The next feature is the ability to set an image as the background of a ListView, whether tiled or a single image. Your My Music folder demonstrates the concept, with a music note image in the lower right hand corner. This project extends the standard ListView with the help of the Windows API to give a more feature rich control.

Code

All the dirty work happens in the ListviewAPI class. Don’t be intimidated if you’ve never used any Windows API. The code simply wraps the SendMessage API using a handful of overrides. The rest is just constants required by the API (documentation available on MSDN).

I’ll spare a long explanation. Download the test project and see for yourself. I included a bitmap file (Note.bmp) to use for setting the background image. You’ll notice, there is extra padding at the bottom of the bitmap. This is because setting the image yOffsetPercent to 100 causes the image to drop below the bottom of the ListView. However, setting the offset to 99 or less causes strange positioning when resizing the window.

History

  • May 25, 2004 - Support for bolded group headers

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer PageLabs
United States United States
I'm the founder of PageLabs, a web-based performance and SEO optimization site.

Give your site a boost in performance, even take a free speed test!

http://www.pagelabs.com

Comments and Discussions

 
GeneralAwesome Control Pin
tonybee7208-Dec-04 5:59
tonybee7208-Dec-04 5:59 
GeneralRe: Awesome Control Pin
TylerBrinks26-Dec-04 6:08
TylerBrinks26-Dec-04 6:08 
QuestionIt doesn't work on Win2K? Pin
Tung Nguyen4-Nov-04 17:03
Tung Nguyen4-Nov-04 17:03 
AnswerRe: It doesn't work on Win2K? Pin
Anonymous5-Nov-04 4:28
Anonymous5-Nov-04 4:28 
AnswerRe: It doesn't work on Win2K? Pin
Sana Sano5-Mar-06 15:02
Sana Sano5-Mar-06 15:02 
GeneralVS.NET 2005 does exactly this Pin
benneh25-Oct-04 21:04
benneh25-Oct-04 21:04 
GeneralRe: VS.NET 2005 does exactly this Pin
TylerBrinks26-Dec-04 6:11
TylerBrinks26-Dec-04 6:11 
GeneralGreat Job! Pin
tupacs0118-Oct-04 17:43
tupacs0118-Oct-04 17:43 
GeneralRe: Great Job! Pin
Anonymous19-Oct-04 12:01
Anonymous19-Oct-04 12:01 
GeneralBackground Colour of ListViewItem Pin
focus_nz7-Oct-04 17:05
focus_nz7-Oct-04 17:05 
GeneralRe: Background Colour of ListViewItem Pin
focus_nz7-Oct-04 17:34
focus_nz7-Oct-04 17:34 
GeneralRe: Background Colour of ListViewItem Pin
Javier M27-Aug-05 7:17
Javier M27-Aug-05 7:17 
GeneralVB.NET Pin
DarkMercenary29-Sep-04 8:24
DarkMercenary29-Sep-04 8:24 
GeneralRe: VB.NET Pin
Anonymous2-Nov-04 5:41
Anonymous2-Nov-04 5:41 
GeneralMDI Application Pin
basemap17-Aug-04 0:05
basemap17-Aug-04 0:05 
Questionclick on listview item? Pin
Ronni Marker22-Jul-04 3:46
Ronni Marker22-Jul-04 3:46 
AnswerRe: click on listview item? Pin
TylerBrinks24-Jul-04 10:57
TylerBrinks24-Jul-04 10:57 
GeneralRe: click on listview item? Pin
Mohammad Ibrahim Malik2-Sep-04 3:05
Mohammad Ibrahim Malik2-Sep-04 3:05 
GeneralRe: click on listview item? Pin
TylerBrinks2-Sep-04 4:33
TylerBrinks2-Sep-04 4:33 
GeneralRe: click on listview item? Pin
Mohammad Ibrahim Malik2-Sep-04 21:13
Mohammad Ibrahim Malik2-Sep-04 21:13 
QuestionUsing custom grouping breaks images - any ideas? Pin
el Powlo®13-Jul-04 8:22
el Powlo®13-Jul-04 8:22 
AnswerRe: Using custom grouping breaks images - any ideas? Pin
TylerBrinks24-Jul-04 10:56
TylerBrinks24-Jul-04 10:56 
GeneralSmall bug fix Pin
Kabal3038-Jul-04 20:10
Kabal3038-Jul-04 20:10 
GeneralMFC/C++ .NET application Pin
Member 14531110-Jun-04 11:45
Member 14531110-Jun-04 11:45 
GeneralRe: MFC/C++ .NET application Pin
TylerBrinks10-Jun-04 17:31
TylerBrinks10-Jun-04 17:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.