Link to home
Start Free TrialLog in
Avatar of sternocera
sternocera

asked on

MFC: What CListCtrl function displays a windows explorer style header button?

I want to display a ClistView's column header, in the style of windows explorer. I've obtained a pointer to the CListCtrl's corresponding CHeaderCtrl:

      CListCtrl& theCtrl = GetListCtrl();
      theCtrl.SetExtendedStyle(LVS_REPORT);
      CHeaderCtrl* HeaderCtrl = theCtrl.GetHeaderCtrl();

I understand that some member function of CListCtrl displays the column header, but I don't know which one.

Please advise,
Regards,
Sternocera
Avatar of mahesh1402
mahesh1402
Flag of India image

to set headers attributes you need to use CHeaderCtrl::SetItem()

See for more :
http://www.codeproject.com/listctrl/headerctrl.asp

-MAHESH
Avatar of sternocera
sternocera

ASKER

Mahesh,

I've downloaded this very tutorial already. It says "The fact that the CHeaderCtrl's visibility is managed by the CListCtrl will become important later when we address message handling."

This is how I learned that CHeaderCtrl's visibility is managed by a CListCtrl member function. How do I actually display the CHeaderCtrl?,
Regards,
Sternocera
>>How do I actually display the CHeaderCtrl?,

I am not getting you...When the list view control is in the report style it usually displays a header control to label the columns. This header control is a embedded child window of the list view control ... you can get pointer to that one as u did above

-MAHESH
and that will not appear unless you create columns !
I have created columns.
Mahesh,
Here is the OnInitialUpdate() function:
void CMyListView::OnInitialUpdate()
{
      CListView::OnInitialUpdate();



      // Gain a reference to the list control itself
      CListCtrl& theCtrl = GetListCtrl();
      theCtrl.SetExtendedStyle(LVS_REPORT);
      CHeaderCtrl* HeaderCtrl = theCtrl.GetHeaderCtrl();
      
   // Insert a column. This override is the most convenient.
   theCtrl.InsertColumn(0, _T("Player Name"), LVCFMT_LEFT);
   theCtrl.InsertColumn(0, _T("Player team"), LVCFMT_LEFT);
      
   theCtrl.InsertItem(0, "an entry");
      theCtrl.InsertItem(1, "another entry");

   // Set reasonable widths for our columns
   theCtrl.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
   theCtrl.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER);
}

I set the style to LVS_REPORT through SetExtendedStyle,  yet I can't see any column headers.

Why do you think that is?
Thanks
what if u try with using LVCOLUMN struct like :

  LVCOLUMN col;
   col.mask = LVCF_FMT | LVCF_TEXT;
   col.pszText = _T("Player Name");
   col.fmt = LVCFMT_LEFT;
   theCtrl.InsertColumn(1, &col);

-MAHESH
Nothing happens...
Thanks
ASKER CERTIFIED SOLUTION
Avatar of mahesh1402
mahesh1402
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That works! Thanks again, Mahesh.
Thats cause LVS_REPORT is not extended style..setting normally or using ModifyStyle should work.

-MAHESH
Right, thanks