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
sternoceraAsked:
Who is Participating?
 
mahesh1402Commented:
will you truy modifying your style to LVS_REPORT using ModifyStyle() instead of theCtrl.SetExtendedStyle(LVS_REPORT); ?

theCtrl.ModifyStyle(0,LVS_REPORT);

-MAHESH
0
 
mahesh1402Commented:
to set headers attributes you need to use CHeaderCtrl::SetItem()

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

-MAHESH
0
 
sternoceraAuthor Commented:
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
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
mahesh1402Commented:
>>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
0
 
mahesh1402Commented:
and that will not appear unless you create columns !
0
 
sternoceraAuthor Commented:
I have created columns.
0
 
sternoceraAuthor Commented:
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
0
 
mahesh1402Commented:
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
0
 
sternoceraAuthor Commented:
Nothing happens...
Thanks
0
 
sternoceraAuthor Commented:
That works! Thanks again, Mahesh.
0
 
mahesh1402Commented:
Thats cause LVS_REPORT is not extended style..setting normally or using ModifyStyle should work.

-MAHESH
0
 
sternoceraAuthor Commented:
Right, thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.