Click here to Skip to main content
15,880,427 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 369K   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

 
Generalsort within groups Pin
umeca745-Jan-06 22:49
umeca745-Jan-06 22:49 
GeneralXPListViewItem.UseItemStyleForSubItems is ignored Pin
Yax Ku'k Mo5-Jan-06 10:54
Yax Ku'k Mo5-Jan-06 10:54 
GeneralChange row color Pin
[Neno]21-Nov-05 10:45
[Neno]21-Nov-05 10:45 
GeneralStackOverFlow Pin
rafabgood19-Sep-05 2:48
rafabgood19-Sep-05 2:48 
GeneralRe: StackOverFlow Pin
rafabgood19-Sep-05 3:00
rafabgood19-Sep-05 3:00 
GeneralRe: StackOverFlow Pin
Moshe Taieb24-Oct-06 1:56
Moshe Taieb24-Oct-06 1:56 
GeneralRe: StackOverFlow Pin
lornen25-Dec-06 17:05
lornen25-Dec-06 17:05 
GeneralCompile Error Pin
Simon Pearson14-Sep-05 1:04
Simon Pearson14-Sep-05 1:04 
GeneralStackoverflowException Pin
laszlo varga2-Sep-05 11:23
laszlo varga2-Sep-05 11:23 
GeneralRe: StackoverflowException Pin
iixulf23-Mar-06 18:51
iixulf23-Mar-06 18:51 
GeneralUsing or not using Application.EnableVisualStyles(); Pin
Paulo Aboim Pinto4-Aug-05 0:57
Paulo Aboim Pinto4-Aug-05 0:57 
GeneralRe: Using or not using Application.EnableVisualStyles(); Pin
Paulo Aboim Pinto4-Aug-05 1:18
Paulo Aboim Pinto4-Aug-05 1:18 
GeneralIndicating that list is empty Pin
Paulo Aboim Pinto4-Aug-05 0:54
Paulo Aboim Pinto4-Aug-05 0:54 
GeneralGroup Headers Pin
Calum McLellan10-Jul-05 21:58
Calum McLellan10-Jul-05 21:58 
GeneralRe: Group Headers Pin
Calum McLellan15-Jul-05 9:39
Calum McLellan15-Jul-05 9:39 
GeneralSelection problem Pin
Mific996-Jul-05 7:58
Mific996-Jul-05 7:58 
GeneralListViewItem DesignMode Pin
dEv!L's butt30-Jun-05 21:26
dEv!L's butt30-Jun-05 21:26 
QuestionCollapsable group? Pin
kozmoz14-Jun-05 1:17
kozmoz14-Jun-05 1:17 
AnswerRe: Collapsable group? Pin
TylerBrinks15-Jun-05 4:30
TylerBrinks15-Jun-05 4:30 
GeneralAdd group manuel Pin
deltadk14-Apr-05 22:15
deltadk14-Apr-05 22:15 
GeneralEnable the context menu only when an item is selected Pin
vxje6-Apr-05 23:44
vxje6-Apr-05 23:44 
Generalbackground image Pin
marcplatvoet2-Mar-05 5:06
marcplatvoet2-Mar-05 5:06 
GeneralUsing foreach statement Pin
adamhb15-Dec-04 16:18
adamhb15-Dec-04 16:18 
GeneralRe: Using foreach statement Pin
TylerBrinks26-Dec-04 6:09
TylerBrinks26-Dec-04 6:09 
GeneralRe: Using foreach statement Pin
moon4415-Apr-05 11:09
moon4415-Apr-05 11:09 

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.