在列表控件中获取列名 [英] Get column name in a list control

查看:78
本文介绍了在列表控件中获取列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个列表控件-报告视图,具有3列.如何获取列名?我尝试了GetColumn().但是它没有返回值.
代码部分如下所示.

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.

LVCOLUMN lvColInfo ;	
ZeroMemory(&lvColInfo, sizeof(lvColInfo));
m_MyListCtrl.GetColumn(0, &lvColInfo);

推荐答案

="http://msdn.microsoft.com/zh-cn/library/xbwzyda0(VS.80).aspx"> CListCtrl :: GetColumn(MFC) [ LVCOLUMN结构(Windows) [
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:

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);


如果您需要检索文本列,则必须正确初始化LVCOLUMN结构:
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);


这篇关于在列表控件中获取列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆