Solved

Header Name of the listview?

Posted on 2000-04-17
7
302 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 114
Doc'in system (example?) BA 7 79
bigDiff challenge 17 75
sumHeights2  challenge 7 78
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now