?
Solved

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

Posted on 2007-07-30
12
Medium Priority
?
686 Views
Last Modified: 2013-12-14
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
0
Comment
Question by:sternocera
  • 6
  • 6
12 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 19591552
to set headers attributes you need to use CHeaderCtrl::SetItem()

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

-MAHESH
0
 

Author Comment

by:sternocera
ID: 19591566
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 19591655
>>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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 22

Expert Comment

by:mahesh1402
ID: 19591663
and that will not appear unless you create columns !
0
 

Author Comment

by:sternocera
ID: 19591667
I have created columns.
0
 

Author Comment

by:sternocera
ID: 19591689
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
 
LVL 22

Expert Comment

by:mahesh1402
ID: 19592239
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
 

Author Comment

by:sternocera
ID: 19592246
Nothing happens...
Thanks
0
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 2000 total points
ID: 19592328
will you truy modifying your style to LVS_REPORT using ModifyStyle() instead of theCtrl.SetExtendedStyle(LVS_REPORT); ?

theCtrl.ModifyStyle(0,LVS_REPORT);

-MAHESH
0
 

Author Comment

by:sternocera
ID: 19592334
That works! Thanks again, Mahesh.
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 19592365
Thats cause LVS_REPORT is not extended style..setting normally or using ModifyStyle should work.

-MAHESH
0
 

Author Comment

by:sternocera
ID: 19592371
Right, thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question