Click to See Complete Forum and Search --> : Detecting Column Header Clicked With CListCtrl


Mark E
May 22nd, 1999, 07:21 PM
Hi,

I need to detect when a header is clicked in a clistctrl, which is easy with onclicked(). I then
need to find the index of the header that was clicked And change the label for that header. Is there an easy way to do this?

Thanks for your help,

- Mark

Guodandan
May 22nd, 1999, 08:25 PM
You should use Message Reflection notification of LVN_COLUMNCLICK. Add following line between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP macro pairs,

ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick)



and add a member function in your view class,

void CMyView::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult);




To know which header column is clicked, do following,

NM_LISTVIEW *phdn = (NM_LISTVIEW *) pNMHDR;
int iColumnClicked = phdn->iSubItem;




This does work in my codes, and wish u good luck.






--
mailto://chinaufo@263.net

Mark E
May 22nd, 1999, 08:46 PM
Thanks very much,

I was getting so frustrated that I can't find any help to tell me that 1 **** command.

Thanks again,

- Mark

Masaaki
May 23rd, 1999, 01:18 AM
Hi.

This is a latter part of code to change the title of header
control. This is one approach.

You will find more clues from this site - CListView control
section.

//Chage the title to "Test"
CHeaderCtrl* pHeader =(CHeaderCtrl*)GetListCtrl().GetDlgItem(0);
HD_ITEM head;

pHeader->GetItem(colIndex, &head);
head.mask = HDI_TEXT;
head.fmt = HDF_IMAGE | HDF_STRING;
head.pszText = "Test";
pHeader->SetItem(colIndex, &head);

Regards.
-Masaaki Onishi-