Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ListView Grouping XP Style

0.00/5 (No votes)
27 May 2004 12  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here