cplau
asked on
Header Name of the listview?
Hi all,
How can I get name of the header at the listview?
Thanks!!!
How can I get name of the header at the listview?
Thanks!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(nMaxHead erLength);
HdItem.cchTextMax = nMaxHeaderLength;
// retrieve the data
pHeader->GetItem(nColumnIn dex, &HdItem);
// release the Buffer and finish
Caption.ReleaseBuffer();
TRACE("The caption of the Heading Number %i is :%s\n", nColumnIndex, 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(nMaxHead
HdItem.cchTextMax = nMaxHeaderLength;
// retrieve the data
pHeader->GetItem(nColumnIn
// release the Buffer and finish
Caption.ReleaseBuffer();
TRACE("The caption of the Heading Number %i is :%s\n", nColumnIndex, Caption);
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(nMaxHead erLength);
HdItem.cchTextMax = nMaxHeaderLength;
// retrieve the data
pHeader->GetItem(nColumnIn dex, &HdItem);
// release the Buffer and finish
Caption.ReleaseBuffer();
TRACE("The caption of the Heading Number %i is :%s\n", nColumnIndex, 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(nMaxHead
HdItem.cchTextMax = nMaxHeaderLength;
// retrieve the data
pHeader->GetItem(nColumnIn
// release the Buffer and finish
Caption.ReleaseBuffer();
TRACE("The caption of the Heading Number %i is :%s\n", nColumnIndex, Caption);
you need to fill in your HDITEM more as proskig has suggested
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(nHeaderL ength);
lvc.cchTextMax = nHeaderLength;
m_listctrl.GetColumn(i, &lvc);
strName.ReleaseBuffer();
Here is the example:
CString strHeaderName;
int nHeaderLength = 100;
lvc.mask = LVCF_TEXT;
lvc.pszText = strName.GetBuffer(nHeaderL
lvc.cchTextMax = nHeaderLength;
m_listctrl.GetColumn(i, &lvc);
strName.ReleaseBuffer();
Correction:
CString strHeaderName;
int nHeaderLength = 100;
lvc.mask = LVCF_TEXT;
lvc.pszText = strName.GetBuffer(nHeaderL ength);
lvc.cchTextMax = nHeaderLength;
m_listctrl.GetColumn(0, &lvc);
strName.ReleaseBuffer();
lvc.pszText will contain the name of the Header of column 1.
CString strHeaderName;
int nHeaderLength = 100;
lvc.mask = LVCF_TEXT;
lvc.pszText = strName.GetBuffer(nHeaderL
lvc.cchTextMax = nHeaderLength;
m_listctrl.GetColumn(0, &lvc);
strName.ReleaseBuffer();
lvc.pszText will contain the name of the Header of column 1.
ASKER
I have already tried this but the program were forced to exit.
//////////////////////////
//////////////////////////
CHeaderCtrl* pHeader = (CHeaderCtrl*)wndList.GetD
HD_ITEM headerinfo;
headerinfo.mask = HDI_TEXT;
if (!(pHeader->GetItem(0,&hea
AfxMessageBox("ERROR");
TRACE("HEADER NAME = %s\n", headerinfo.pszText);
//////////////////////////
//////////////////////////
What errors had I made?
Thanks for your opinion!!!