Solved

Header Name of the listview?

Posted on 2000-04-17
7
309 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 84
Unix / Linux grid computing 5 156
Named range not carried over 10 63
has77  challenge 9 83
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: 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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

776 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