如何在ClistCtrl 某列添加chenkbox?

clwk 2009-12-15 10:44:36
如何在ClistCtrl 的某一列添加chenkbox。
ClistCtrl是report风格。

SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES);
我做了这样的设置,但是没有看见checkbox出现。

...全文
158 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2009-12-21
  • 打赏
  • 举报
回复
那个check box不过是state image而已。你可以用subitem的图像来模拟。
maple_zhj 2009-12-17
  • 打赏
  • 举报
回复
你尝试插入一行记录看看,

是否列表行首位置有 一段空白?

个人感觉,有可能你使用了别人重载过 DrawItem()

但没有去实现重绘 CheckBox 框。


第二,尝试不使用 重载的类,直接 用 CListCtrl 类,试一下,

是否问题依旧?
clwk 2009-12-17
  • 打赏
  • 举报
回复
还是一样,没反应,只是宽度有点变化,还是没出现复选框。
anydaily 2009-12-17
  • 打赏
  • 举报
回复
m_listctrk.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES)
clwk 2009-12-17
  • 打赏
  • 举报
回复
void CSortHeaderCtrl::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
// attath to the device context.
CDC dc;
VERIFY( dc.Attach( lpDrawItemStruct->hDC ) );

// save the device context.
const int iSavedDC = dc.SaveDC();

// get the column rect.
CRect rc( lpDrawItemStruct->rcItem );

// set the clipping region to limit drawing within the column.
CRgn rgn;
VERIFY( rgn.CreateRectRgnIndirect( &rc ) );
(void)dc.SelectObject( &rgn );
VERIFY( rgn.DeleteObject() );

// draw the background,
CBrush brush( GetSysColor( COLOR_3DFACE ) );
dc.FillRect( rc, &brush );

// get the column text and format.
TCHAR szText[ 256 ];
HD_ITEM hditem;

hditem.mask = HDI_TEXT | HDI_FORMAT;
hditem.pszText = szText;
hditem.cchTextMax = 255;

VERIFY( GetItem( lpDrawItemStruct->itemID, &hditem ) );

// determine the format for drawing the column label.
UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS ;

if( hditem.fmt & HDF_CENTER)
uFormat |= DT_CENTER;
else if( hditem.fmt & HDF_RIGHT)
uFormat |= DT_RIGHT;
else
uFormat |= DT_LEFT;

// adjust the rect if the mouse button is pressed on it.
if( lpDrawItemStruct->itemState == ODS_SELECTED )
{
rc.left++;
rc.top += 2;
rc.right++;
}

CRect rcIcon( lpDrawItemStruct->rcItem );
const int iOffset = ( rcIcon.bottom - rcIcon.top ) / 4;

// adjust the rect further if the sort arrow is to be displayed.
if( lpDrawItemStruct->itemID == (UINT)m_iSortColumn )
rc.right -= 3 * iOffset;

rc.left += iOffset;
rc.right -= iOffset;

// draw the column label.
if( rc.left < rc.right )
(void)dc.DrawText( szText, -1, rc, uFormat );

// draw the sort arrow.
if( lpDrawItemStruct->itemID == (UINT)m_iSortColumn )
{
// set up the pens to use for drawing the arrow.
CPen penLight( PS_SOLID, 1, GetSysColor( COLOR_3DHILIGHT ) );
CPen penShadow( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ) );
CPen* pOldPen = dc.SelectObject( &penLight );

if( m_bSortAscending )
{
// draw the arrow pointing upwards.
dc.MoveTo( rcIcon.right - 2 * iOffset, iOffset);
dc.LineTo( rcIcon.right - iOffset, rcIcon.bottom - iOffset - 1 );
dc.LineTo( rcIcon.right - 3 * iOffset - 2, rcIcon.bottom - iOffset - 1 );
(void)dc.SelectObject( &penShadow );
dc.MoveTo( rcIcon.right - 3 * iOffset - 1, rcIcon.bottom - iOffset - 1 );
dc.LineTo( rcIcon.right - 2 * iOffset, iOffset - 1);
}
else
{
// draw the arrow pointing downwards.
dc.MoveTo( rcIcon.right - iOffset - 1, iOffset );
dc.LineTo( rcIcon.right - 2 * iOffset - 1, rcIcon.bottom - iOffset );
(void)dc.SelectObject( &penShadow );
dc.MoveTo( rcIcon.right - 2 * iOffset - 2, rcIcon.bottom - iOffset );
dc.LineTo( rcIcon.right - 3 * iOffset - 1, iOffset );
dc.LineTo( rcIcon.right - iOffset - 1, iOffset );
}

// restore the pen.
(void)dc.SelectObject( pOldPen );
}

// restore the previous device context.
VERIFY( dc.RestoreDC( iSavedDC ) );

// detach the device context before returning.
(void)dc.Detach();
}

好象是DrawItem()被重载过,是上面的这段代码,我该如何修改呢?
wb_rock 2009-12-16
  • 打赏
  • 举报
回复
SetItem( iIndex, iColumn, LVIF_TEXT, pszText, 0, 0, 0, 0 )
设置一下最后一个数值,写个200试试
clwk 2009-12-16
  • 打赏
  • 举报
回复
没戏。
clwk 2009-12-15
  • 打赏
  • 举报
回复
有人吗?
clwk 2009-12-15
  • 打赏
  • 举报
回复

SetItem( iIndex, iColumn, LVIF_TEXT, pszText, 0, 0, 0, 0 )
的设置会不会有关系呢?
clwk 2009-12-15
  • 打赏
  • 举报
回复
没错,是report。
MoXiaoRab 2009-12-15
  • 打赏
  • 举报
回复
是Report风格?
clwk 2009-12-15
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 clwk 的回复:]
用了
SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES);

但是为什么每一行前面都没有复选框的显示呢?
请教一下。
[/Quote]

我是先用了一个clistctrl的类,用来改变每一行的颜色,然后想把checkbox加在一列上面,可是我只发现列表的宽度有了变化,但是复选框没有显示出来,不知道是哪里出了问题。
Dingnifei123 2009-12-15
  • 打赏
  • 举报
回复
http://www.codeproject.com/KB/wtl/WTL_ListCtrl.aspx
whs1980 2009-12-15
  • 打赏
  • 举报
回复
应该会有的
确定是report风格了吗?用下面的代码单独试试.
SetExtendedStyle( LVS_EX_CHECKBOXES);
clwk 2009-12-15
  • 打赏
  • 举报
回复
用了
SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES);

但是为什么每一行前面都没有复选框的显示呢?
请教一下。
clwk 2009-12-15
  • 打赏
  • 举报
回复
这里面我都看过,但是和我的问题不一样。
clwk 2009-12-15
  • 打赏
  • 举报
回复
waiting...

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧