Solved

Header Name of the listview?

Posted on 2000-04-17
7
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

622 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