Click here to Skip to main content
15,882,063 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 369.1K   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

 
GeneralBackground image does not repaint Pin
exeton9-Jun-04 20:54
exeton9-Jun-04 20:54 
GeneralRe: Background image does not repaint Pin
TylerBrinks10-Jun-04 17:29
TylerBrinks10-Jun-04 17:29 
GeneralStack overflow Pin
Gary Thom6-Jun-04 6:34
Gary Thom6-Jun-04 6:34 
GeneralThumbnails Pin
Gary Thom2-Jun-04 9:11
Gary Thom2-Jun-04 9:11 
GeneralRe: Thumbnails Pin
TylerBrinks2-Jun-04 11:52
TylerBrinks2-Jun-04 11:52 
GeneralRe: Thumbnails Pin
Gary Thom2-Jun-04 12:08
Gary Thom2-Jun-04 12:08 
GeneralRe: Thumbnails Pin
Gary Thom2-Jun-04 12:13
Gary Thom2-Jun-04 12:13 
GeneralNice Pin
NormDroid28-May-04 1:01
professionalNormDroid28-May-04 1:01 
GeneralApplication.EnableVisualStyles Pin
Dave Haefliger27-May-04 21:41
Dave Haefliger27-May-04 21:41 
GeneralRe: Application.EnableVisualStyles Pin
TylerBrinks28-May-04 5:40
TylerBrinks28-May-04 5:40 
GeneralRe: Application.EnableVisualStyles Pin
hcihlen10-Jul-04 19:30
hcihlen10-Jul-04 19:30 
GeneralRe: Application.EnableVisualStyles Pin
TylerBrinks11-Jul-04 8:07
TylerBrinks11-Jul-04 8:07 
GeneralRe: Application.EnableVisualStyles Pin
hcihlen11-Jul-04 10:49
hcihlen11-Jul-04 10:49 
GeneralRe: Application.EnableVisualStyles Pin
Xarxus14-Sep-04 5:05
Xarxus14-Sep-04 5:05 
GeneralRe: Application.EnableVisualStyles Pin
TylerBrinks14-Sep-04 5:24
TylerBrinks14-Sep-04 5:24 
GeneralCustom Grouping Pin
Werdna19-May-04 5:56
Werdna19-May-04 5:56 
GeneralRe: Custom Grouping Pin
TylerBrinks20-May-04 4:20
TylerBrinks20-May-04 4:20 
QuestionGreat! Can the group headers be displayed in bold? Pin
Hammer719-May-04 1:50
Hammer719-May-04 1:50 
AnswerRe: Great! Can the group headers be displayed in bold? Pin
TylerBrinks20-May-04 4:16
TylerBrinks20-May-04 4:16 
GeneralVERY cute! Pin
Carl Mercier15-May-04 18:46
Carl Mercier15-May-04 18:46 
GeneralOS Support Pin
GeminiMan15-May-04 17:52
GeminiMan15-May-04 17:52 
GeneralRe: OS Support Pin
TylerBrinks15-May-04 20:35
TylerBrinks15-May-04 20:35 
GeneralRe: OS Support Pin
WillemM16-May-04 23:28
WillemM16-May-04 23:28 
GeneralRe: OS Support Pin
msmits17-May-04 21:02
msmits17-May-04 21:02 

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.