• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

CListCtrl ReportView Header

How do I retrieve the header text in each column from a CListCtrl?  I can retrieve all of the item text but not the header.  I tried redirecting the header but still cannot find a call that will return the text in each column.

CHeaderCtrl* pCtrl = m_List.GetHeaderCtrl();


Thanks,

Janet
0
jaiken
Asked:
jaiken
  • 4
  • 3
1 Solution
 
captainkirkCommented:
I haven't tested this, but try something like this:

HDITEM hi;
CString csText = _T("");
int nPos = 0;

CHeaderCtrl* pCtrl = m_refListCtrl.GetHeaderCtrl();

for (int nIndex = 0; nIndex < pCtrl->GetItemCount(); nIndex++)
{
     pCtrl->GetItem(nPos, &hi);
     csText = hi.pszText;
} // end for
0
 
jaikenAuthor Commented:
That gives an assertion error but thanks for trying.
0
 
captainkirkCommented:
Janet - here's the working version:

char buf[128];
LVCOLUMN lvc;
lvc.mask = LVCF_TEXT;
lvc.pszText = buf;
lvc.cchTextMax = 128;

CString csText = _T("");

CHeaderCtrl* pCtrl = m_refListCtrl.GetHeaderCtrl();
      
int nCount = m_refListCtrl.GetItemCount();

for (int nIndex = 0; nIndex < nCount; nIndex++)
{
     m_refListCtrl.GetColumn(nIndex, &lvc);
     csText = lvc.pszText;
} // end for


Hope that helps...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jaikenAuthor Commented:
Thank you so much Captain.
0
 
jaikenAuthor Commented:
Oh, the only thing that I believe must be changed is the nCount must be equal to the number of columns, not the number of items (= #rows).  
0
 
captainkirkCommented:
right you are...
0
 
jaikenAuthor Commented:
Thank you very much.
0

Featured Post

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.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now