Solved

LVN_COLUMNCLICK and arrow in column header

Posted on 2004-09-27
5
973 Views
Last Modified: 2013-11-20
I think this one should be easy - hopefully! When you sort various lists in applications like explorer (or others) by clicking on the column, then the column will show (add) a little arrow pointing either up or down.

How can I do that? I've got all the sorting etc. figured out, it would just be nice to have the arrow in the column as well.


Thanks!
0
Comment
Question by:Netikus
5 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 12166895
It doesn't come as standard.
What you need to do is have your own class based on CHeaderCtrl which does it's own drawing.
When you create your list control you then need to get the header control it has and subclass it to your customised class.  
Provide a virtual function for the DrawItem and do the drawing there.


I use
      HWND hWndHeader = ::GetDlgItem(m_hWnd, 0);
to get the handle of the header from a list control.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 12167009
0
 
LVL 16

Accepted Solution

by:
nonubik earned 125 total points
ID: 12168051
If we take a look here http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/header/structures/hditem.asp we can see that the version 6.0 of commctrl provides support for the up/down arrow drawing : HDF_SORTDOWN/HDF_SORTUP

For this case some sample code:

BOOL bSortup;
HDITEM      hdrItem;

..... //init the 'sortup' bool

hdrItem.mask = HDI_FORMAT;
GetHeaderControl()->GetItem(0, &hdrItem);
hdrItem.fmt |= (bSortUp)?HDF_SORTUP:HDF_SORTDOWN;
GetHeaderCtrl()->SetItem(0, &hdrItem);
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12168075
>hdrItem.fmt |= (bSortUp)?HDF_SORTUP:HDF_SORTDOWN;
should be
>hdrItem.fmt &= (bSortUp)?~HDF_SORTDOWN:~HDF_SORTUP; //reset the previous flag
>hdrItem.fmt |= (bSortUp)?HDF_SORTUP:HDF_SORTDOWN;      //set the new one
0
 
LVL 1

Author Comment

by:Netikus
ID: 12174308
Thanks everybody. This actually works for me and is very easy to implement.

It's not a problem that it works only on XP - I can definitely live with that.


Thanks.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question