Solved

Header Name of the listview?

Posted on 2000-04-17
7
312 Views
Last Modified: 2013-11-20
Hi all,

How can I get name of the header at the listview?

Thanks!!!
0
Comment
Question by:cplau
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 50 total points
ID: 2725435
if you need to access the header from CListView you first need to get the pointer to the CListCtrl using CListView::GetListCtrl and then you need to get the header control usinf CListCtrl::GetHeaderCtrl you can then access the names using CHeaderCtrl:GetItem
0
 

Author Comment

by:cplau
ID: 2725521
Hi,

I have already tried this but the program were forced to exit.

////////////////////////////////////////////////////////
////////////////////////////////////////////////////////

CHeaderCtrl* pHeader = (CHeaderCtrl*)wndList.GetDlgItem(0);
HD_ITEM headerinfo;
headerinfo.mask = HDI_TEXT;
      
if (!(pHeader->GetItem(0,&headerinfo)))
  AfxMessageBox("ERROR");

TRACE("HEADER NAME = %s\n", headerinfo.pszText);

////////////////////////////////////////////////////////
////////////////////////////////////////////////////////

What errors had I made?

Thanks for your opinion!!!
0
 
LVL 5

Expert Comment

by:proskig
ID: 2725658
Retrieving the column caption


CString Caption; // will recieve the caption

// retrieve the header control see "The header control"
CHeaderCtrl* pHeader = (CHeaderCtrl*) m_listctrl.GetDlgItem(0);
int nMaxHeaderLength=100, // or whatever you need
    nColumnIndex;         // starts with zero, remember to initialize!

// fill the HDITEM structure
HDITEM HdItem;
HdItem.mask = HDI_TEXT; // just get the text
HdItem.pszText = Caption.GetBuffer(nMaxHeaderLength);
HdItem.cchTextMax = nMaxHeaderLength;

// retrieve the data
pHeader->GetItem(nColumnIndex, &HdItem);

// release the Buffer and finish
Caption.ReleaseBuffer();

TRACE("The caption of the Heading Number %i is :%s\n", nColumnIndex, Caption);

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Expert Comment

by:proskig
ID: 2725660
Retrieving the column caption


CString Caption; // will recieve the caption

// retrieve the header control see "The header control"
CHeaderCtrl* pHeader = (CHeaderCtrl*) m_listctrl.GetDlgItem(0);
int nMaxHeaderLength=100, // or whatever you need
    nColumnIndex;         // starts with zero, remember to initialize!

// fill the HDITEM structure
HDITEM HdItem;
HdItem.mask = HDI_TEXT; // just get the text
HdItem.pszText = Caption.GetBuffer(nMaxHeaderLength);
HdItem.cchTextMax = nMaxHeaderLength;

// retrieve the data
pHeader->GetItem(nColumnIndex, &HdItem);

// release the Buffer and finish
Caption.ReleaseBuffer();

TRACE("The caption of the Heading Number %i is :%s\n", nColumnIndex, Caption);

0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2725796
you need to fill in your HDITEM more as proskig has suggested
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2725920
I don't think you have to get a pointer to the HeaderControl to get the header name. Instead use CListCtrl::GetColumn() to accomplish this task.

Here is the example:

CString strHeaderName;
int nHeaderLength = 100;

lvc.mask = LVCF_TEXT;
lvc.pszText = strName.GetBuffer(nHeaderLength);
lvc.cchTextMax = nHeaderLength;
m_listctrl.GetColumn(i, &lvc);

strName.ReleaseBuffer();
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2725931
Correction:

CString strHeaderName;
int nHeaderLength = 100;

lvc.mask = LVCF_TEXT;
lvc.pszText = strName.GetBuffer(nHeaderLength);
lvc.cchTextMax = nHeaderLength;
m_listctrl.GetColumn(0, &lvc);

strName.ReleaseBuffer();

lvc.pszText will contain the name of the Header of column 1.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 53
Creating Labels and Frequency list style reports in SAS code 9 105
deburging in oracle form 12 105
bigDiff challenge 17 126
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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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