Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am having a list control - report view, with 3 columns. How can i get the column name? I tried GetColumn(). But it is not returning the value.
The code part is shown below.
C++
LVCOLUMN lvColInfo ;	
ZeroMemory(&lvColInfo, sizeof(lvColInfo));
m_MyListCtrl.GetColumn(0, &lvColInfo);
Posted
Updated 14-Oct-10 21:11pm
v2

The CListCtrl::GetColumn (MFC)[^] is the right API to use, but you should initialize your lvColInfo with the informations that you want to retrieve (see LVCOLUMN Structure (Windows)[^] for details).
Here below is a code snippet that shows you how to retrieve the name of the column:

C++
TCHAR szName[128]; // This is the buffer where the name will be stored
LVCOLUMN lvColInfo;
ZeroMemory(&lvColInfo, sizeof(lvColInfo)); // This line is not really needed and you can remove it
lvColInfo.mask = LVCF_TEXT;
lvColInfo.pszText = szName;
lvColInfo.cchTextMax = _countof(szName);
m_MyListCtrl.GetColumn(0, &lvColInfo);
 
Share this answer
 
If you need to retrieve the text of a column then you must properly initialize the LVCOLUMN struct:
const INT SIZE = 0x100;
TCHAR szText[SIZE];
LVCOLUMN lvColInfo ;
ZeroMemory(&lvColInfo, sizeof(lvColInfo));
lvColInfo.pszText = szText;
lvColInfo.cchTextMax = SIZE;
lvColInfo.mask = LVCF_TEXT;
m_MyListCtrl.GetColumn(0, &lvColInfo);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900