ListView Coloured Headers Example

Listview Colored Headers

The Listview control of VB 5.0, doesn't let the header control have a colored header buttons. So this code lets you have it, by subclassing the listview and intercepting the header painting to achieve the effect.

Module : mLVClrHdr :

Implementation of Subclassing function and CustomDraw notification of Header control to get colored header elements.

Main Logic:

Step 1 : Subclass the ListView and listen for WM_NOTIFY message from its child ( which is the Header Control)

Step 2 : when you get CustomDraw notification, set the appropriate Colors into the DC, at appropriate painting stage ITEMPREPAINT

Step 3 : The actual paiting work is left for the Default procedure.

Future work: For exotic paiting, you can create a OwnerDraw header button(s) and handle WM_DRAWITEM . It is possible.

I am working on this presently (24/7/99), and shall post it on the Codeguru (VB) site, once it is ready.

This is an enhancement of Colored Listview Items example taken from the Codeguru (VB) site. The original example is by Chris Eastwood. I tried to retain most of the Code, as it is. His code uses a subclassing control, while this uses none. But you have to follow some compulsory steps, so as not to have your VB IDE crashed:-)

** Important & compulsory steps to use this code:

Step 1: Setup the subclass :

Call HooktoLV(listview1.hwnd,True), where listview1 is the Listview control that you want to subclass. Put this line in the Form_load procedure of the form that has this listview.

Step 2 : Set the Foreground and Background colors of the listview header buttons using global variables glHdrTextClr and glHdrBkClr Note that changes take effect only at the next painting cycle.

So, for dynamic changing, use listview.refresh to paint immediately.

Step 3 : Remove the subclass :

Call HooktoLV(Byval 0& , False)

Preffered point of calling this is in Form_QueryUnload. Form_Unload will also work.


Known Bugs : Only one, as far as i could test:

This code paints the header buttons *ONLY*. So if you have the buttons not covering the entire list view, the portion between the last button and listview right edge, still looks "Grey". So, Look for Chris' code elsewhere on Codeguru site to set the last button to occupy the whole of Client area till right-edge of the ListView.

Download Zipped Project File (12k)

Screen shot



Comments

  • How to decrese the row height of ListView in VB.

    Posted by Legacy on 12/19/2002 12:00am

    Originally posted by: Sakshi

    In ListView Control I couldn't get proper output display. The data display in reportview of ListView comes with bigger rows.If you know how to set the row height in output display please tell me.

    • How to decrese the row height of ListView in VB.

      Posted by rajalo on 04/26/2004 05:12am

      Decrease the font size - Guess this will work -)

      Reply
    Reply
  • ListView Problem

    Posted by Legacy on 07/17/2002 12:00am

    Originally posted by: Nishita

    I have three columns in ListView control and if i click on first column header - the text in column header shouls appear in RED color. If you do, can you please send me a sample code or a web site where it shows how to do it. Thanks in advance. Ricky

    Reply
  • List view header color

    Posted by Legacy on 05/23/2002 12:00am

    Originally posted by: Cristina

    when i try to end the application from vb develpment
    environment I'm getting an assertion error.if Anyone
    knows how to solve it please help.
    Thanks in advance.
    Cristina

    Reply
  • Cool, I like this site

    Posted by Legacy on 12/20/2001 12:00am

    Originally posted by: Pingo James

    Thank author for his/her code.

    Reply
  • THANKS!!!

    Posted by Legacy on 06/26/2001 12:00am

    Originally posted by: Alberto Vasquez

    Thanks so much for this code.. I've been trying to find this change and this is the first place I found it at.

    Thanks again!

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

  • On-demand Event Event Date: March 27, 2014 Teams need to deliver quality software faster and need integrated agile planning, task tracking, source control, auto deploy with continuous builds and a configurable process to adapt to the way you work. Rational Team Concert and DevOps Services (JazzHub) have everything you need to build great software, integrated seamlessly together right out of the box or available immediately in the cloud. And with the Rational Team Concert Client, you can connect your …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds