关于CListView如何显示列标题

本文介绍如何在MFC生成的单文档程序中,将CListView的默认图标视图样式更改为报告视图样式,并添加网格线及实现列表项的可选中功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由MFC生成的单文档程序,如果继承了CListView类来显示图的话,默认是style 为 LVS_ICON,如果想改为LVS_REPORT,有以下两种方法:

1.在CXXXView类中添加OnCreate(...)消息响应函数,代码如下

int CXXXView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 lpCreateStruct->style |= LVS_REPORT | LVS_SHOWSELALWAYS;

 if (CListView::OnCreate(lpCreateStruct) == -1)
  return -1;
 
 // TODO: Add your specialized creation code here

 
 return 0;
}

2.修改CXXXView类中虚函数Create(...),代码如下

BOOL CXXX2View::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
 // TODO: Add your specialized code here and/or call the base class
 dwStyle |= LVS_REPORT | LVS_SHOWSELALWAYS | LVS_EX_GRIDLINES;

 

return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}

 

但此时生成的List没有GRIDLINES,且无法被选中,接下来我们需要让我们的CLisView显示GRIDLINES,并能被选中,在CXXX2View::OnInitialUpdate()中添加代码如下:

void CXXXView::OnInitialUpdate()
{
 CListView::OnInitialUpdate();

 

 CListCtrl& lc = GetListCtrl();
 lc.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);LVS_ICON
 

// TODO: You may populate your ListView with items by directly accessing
 //  its list control through a call to GetListCtrl().
}

 

非常好用的CListCtrl加强版。 从CListCtrl继承,完全兼容CListCtrl. 它有以下特性: • The background of the sorted column can be displayed in a different color (like the detailed view of Windows XP Explorer). • The header of the sorted column can display an arrow that indicates the sort direction (like the detailed view of Windows XP Explorer). • You can give the user the opportunity to hide or redisplay selected columns by just clicking on the header control with the right mouse button (see picture below). • You can hide or redisplay a selected column entirely. • In contrast to the original list view control, the first column can have the LVCFMT_CENTER or LVCFMT_RIGHT style, too. For this feature, the list view control must have the LVS_OWNERDRAWFIXED style. • The label attributes state icon, small icon, and selection can always be shown in the leftmost column, independent of the order of the columns. For this feature, the listview control must have the LVS_OWNERDRAWFIXED style. • You can supply tooltips not only for the whole item, but also for the small icon, the state icon, and each subitem label. • The extended styles LVS_EX_CHECKBOXES, LVS_EX_ONECLICKACTIVATE, LVS_EX_SUBITEMIMAGES, LVS_EX_TWOCLICKACTIVATE, and LVS_EX_UNDERLINEHOT will be supported even if the list view control has the LVS_OWNERDRAWFIXED style. • If the LVS_EX_CHECKBOXES style has been applied and a selected item will be checked/unchecked, all other selected items will be checked/unchecked, too. • If the LVS_EX_LABELTIP style has been applied, not only the partially hidden text of the item label will be unfolded but also the partially hidden text of each subitem label. Note: The LVS_EX_LABELTIP style will be supported under all operating systems. • Tooltips and expanded labels can be displayed simultaneously. • The current state of the list view control (column widths, column order, hidden columns, and sort column and direction) can be saved and restored.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值