Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List control header

Status
Not open for further replies.

Pinpoint

Programmer
Dec 23, 2001
49
GB
Hi,
Can anyone help with a problem I'm having with a list control. I want to be able to sort the list on each column, by clicking on the column header. But although I've added a function for the HDN_ITEMCLICK message nothing happens. I cant even trace the function, so I think it's not activating. The list is report style, with column headers enabled. And if it were to work, I also cant see how the function returns the column whose header is being clicked on...
Thanks
Pinpoint.
 
Hi

Here is how I did it ... I derived a class from the CHeaderCtrl class.
I overwrote the OnLButtonDown function as follows:

// Check for Mouse Hit in a Column Header

HD_HITTESTINFO hd_hittestinfo;

hd_hittestinfo.pt = point;

SendMessage( HDM_HITTEST, 0, ( LPARAM) ( &hd_hittestinfo));

if( hd_hittestinfo.flags == HHT_ONHEADER)
m_nColNdx = hd_hittestinfo.iItem;
else
m_nColNdx = -1;

CHeaderCtrl::OnLButtonDown(nFlags, point);

You could also overwrite OnRButtonDown and make a menu appears.

Thierry
EMail: Thierry.Marneffe@swing.be
Web Site:
 
Thierry,
Thanks for that. One question. I have to assign the header control object to my list control with GetHeaderCtrl(). But this doesnt accept the new Header control class. So do I need a new list control class too, with the GetHeaderCtrl function overridden ? (I have tried doing this, but cannot add an object of the new list control class to my dialog. I've tried adding it as a custom control, but this doesnt seem to do anything - my dialog no longer runs).
Regards,
Pinpoint
 
Hi

Yes You're right.
To be honnest, I did it long ago, so I looked back some code I wrote and here is what I found:

I derived one class from CListCtrl that I called CExtListCtrl and one from CHeaderCtrl that I called CExtHeaderCtrl
In the CExtListCtrl, I declare the CExtHeaaderCtrl.

Then I overwrote the PresubclassWindow as show below:

void CExtListCtrl::preSubclassWindow()
{
CListCtrl::preSubclassWindow();

m_ExtHeaderCtrl.SubclassWindow( ::GetDlgItem( m_hWnd, 0));
}

HTH

Thierry
EMail: Thierry.Marneffe@swing.be
Web Site:
 
Hi,
Still having problems getting my new ListCtrl2 to display on my dialog. Am creating it dynamically as follows:

CRect r_List(179, 80, 322, 193); // posn for listctrl2 CListCtrl2 list2;
list2.Create(LVS_REPORT|LVS_SINGLESEL|LVS_SORTASCENDING| LVS_ALIGNLEFT, r_List, this, 990); // create listctrl2

CListCtrl2 * p_ListFiles2;
p_ListFiles2 = &list2;
p_ListFiles2->GetHeaderCtrl(); // set up HdrCtrl2 derived class...
p_ListFiles2->SetImageList(&m_imagelist, LVSIL_SMALL);p_ListFiles2->InsertColumn(0, "File", LVCFMT_LEFT, 124);
p_ListFiles2->InsertColumn(1, "Modified", LVCFMT_LEFT, 100);

No errors but nothing shows on the dialog. Anything obvious ?
Cheers.
 
I think the easy way for you to handle the column click event is to add a LVN_COLUMNCLICK message handler in your program.
void YourDialog::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

// get the column
int _selColumn = pNMListView->iSubItem;
...
}
 
That works like a dream !
Thanks a lot.
Pinpoint
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top