Solved

LVN_COLUMNCLICK and arrow in column header

Posted on 2004-09-27
5
931 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 114
java ^ examples 8 57
Annoying "thing" blocks my view 4 51
Change to event 1 73
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now