首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

listcontrol的中只能高亮选中第一列,怎么高亮选中其他列

2013-03-01 
listcontrol的中只能高亮选中第一列,如何高亮选中其他列listcontrol的中只能高亮选中第一列,如何高亮选中

listcontrol的中只能高亮选中第一列,如何高亮选中其他列
listcontrol的中只能高亮选中第一列,如何高亮选中其他列,另外还有一问,如何使得第一列也不高亮选中,请高手回答,3x。
[解决办法]
ListControl有个风格,叫做LVS_EX_FULLROWSELECT 

你基本可以结贴了。
[解决办法]
可以试试:


m_List.SetSelectionMark(nItemIdx);  // nItemIdx为高亮显示的行号;
m_List.SetFocus();
m_List.EnsureVisible( nItemIdx, FALSE );
m_List.SetItemState( nItemIdx, LVIS_SELECTED
[解决办法]
LVIS_FOCUSED, LVIS_SELECTED
[解决办法]
LVIS_FOCUSED );





[解决办法]
引用:
引用:ListControl有个风格,叫做LVS_EX_FULLROWSELECT 

你基本可以结贴了。
我想要的结果是单击某一行的某一列,只有改subitem高亮,并不是整行都高亮,另外我想要实现的是单击时才高亮


那只有自绘了。没有风格是管这个的。
[解决办法]
引用:
ListControl有个风格,叫做LVS_EX_FULLROWSELECT 

你基本可以结贴了。


这个是 整行选中 吧。1楼的说法不可行吗?
如果是要设置单独的某个单元格颜色,就要自绘吧。
重载ListCtrl的NM_CUSTOMDRAW消息,然后进行处理。
或者可以google找一下别人实现好的,比如实施:
http://download.csdn.net/download/crystalyay/2573448
[解决办法]
重载NM_CUSTOMDRAW消息:
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)

然后在OnCustomDraw里面自己处理(这个是贴的一个别人的实现的一部分,楼主可以google,有很多现成的类可以参考):
void CColorCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
//draw each item.set txt color,bkcolor....
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);

// Take the default processing unless we set this to something else below.
*pResult = CDRF_DODEFAULT;

// First thing - check the draw stage. If it's the control's prepaint
// stage, then tell Windows we want messages for every item.

if (pLVCD->nmcd.dwDrawStage == CDDS_PREPAINT)
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
{
// This is the notification message for an item.  We'll request
// notifications before each subitem's prepaint stage.

*pResult = CDRF_NOTIFYSUBITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT 
[解决办法]
 CDDS_SUBITEM))
{
// This is the prepaint stage for a subitem. Here's where we set the
// item's text and background colors. Our return value will tell
// Windows to draw the subitem itself, but it will use the new colors
// we set here.

int nItem = static_cast<int> (pLVCD->nmcd.dwItemSpec);
int nSubItem = pLVCD->iSubItem;



ItemData *pXLCD = (ItemData *) pLVCD->nmcd.lItemlParam;
ASSERT(pXLCD);

COLORREF crText  = crWindowText;
COLORREF crBkgnd = crWindow;

if (pXLCD)
{
crText  = (pXLCD->crText)[nSubItem];
crBkgnd = (pXLCD->crBak)[nSubItem];
}

// store the colors back in the NMLVCUSTOMDRAW struct
pLVCD->clrText = crText;
pLVCD->clrTextBk = crBkgnd;

CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
CRect rect;
GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, rect);
if (GetItemState(nItem, LVIS_SELECTED))
DrawText(nItem, nSubItem, pDC, crHighLightText, crHighLight , rect);
else
DrawText(nItem, nSubItem, pDC, crText, crBkgnd, rect);

*pResult = CDRF_SKIPDEFAULT;// We've painted everything.
}
}

热点排行