Click to See Complete Forum and Search --> : MFC: ClistCtrl::GetSelectedColumn


sigomatix
April 3rd, 2003, 02:54 PM
Hi,

I'm currently using a CListCtrl for my application, thus i would like to sort items when the user click on an column header.

I manage to detect the click action, but i don't know how to retrieve the selected column...the msdn talk about a GetSelectedColumn method in the CListCtrl class, that's cool but when i type the call to this method and i compile i've an:

:\myprog\mator\DialogPlayer.cpp(225) : error C2039: 'GetSelectedColumn' : is not a member of 'CListCtrl'
c:\program files\microsoft visual studio\vc98\mfc\include\afxcmn.h(177) : see declaration of 'CListCtrl'

:( how can i do ?

Thanks for help !

HeartBreakKid
April 3rd, 2003, 03:04 PM
ON_NOTIFY(LVN_COLUMNCLICK, IDC_MYLIST, OnLvnColumnclickMyList)

void MyView::OnLvnColumnclickMyList(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);

// pNMLV->iSubItem is the column index
_myList.SortItems(CompareFun, pNMLV->iSubItem);

*pResult = 0;
}

sigomatix
April 3rd, 2003, 03:12 PM
Yeah thanx a lot !

Mike Harnad
April 3rd, 2003, 03:13 PM
To detect a click on the column header, you can respond to a HDN_ITEMCLICK message. It is sent via ON_NOTIFY. For example,

ON_NOTIFY( HDN_ITEMCLICK, 0, OnClickListColumnHdr )

The handler appears like this:

void CMyDlg::OnClickListColumnHdr(NMHDR* pNotifyStruct, LRESULT* pResult)

pNotifyStruct contains a member called 'iItem' that indicates the column that was clicked.