发这个帖子之前,我已经发过一个,请先看看:
http://community.csdn.net/Expert/topic/3704/3704297.xml?temp=3.532046E-02我大概已经知道,可以重载OnCustomDraw函数来实现ListCtrl中颜色的重画。并且通过下面的代码来指定改变某行的颜色,lplvcd->nmcd.dwItemSpec == nLine //nLine表示listctrl第几行。小弟现在要解决的问题是:
当点击Column时,ListCtrl会对里面的数据排序。那么在排序过程中,该行的颜色和该行的数据怎么保持同步?具体的步骤是怎么样的?我找到了几个类似的例子,但是很复杂,我研究了一个礼拜天还是没有什么进展。一个字“菜”,两个字“很菜”。小弟特来请教,请高手指点,谢谢!学习,关注……
http://community.csdn.net/Expert/topic/3704/3704297.xml?temp=3.532046E-02我大概已经知道,可以重载OnCustomDraw函数来实现ListCtrl中颜色的重画。并且通过下面的代码来指定改变某行的颜色,lplvcd->nmcd.dwItemSpec == nLine //nLine表示listctrl第几行。小弟现在要解决的问题是:
当点击Column时,ListCtrl会对里面的数据排序。那么在排序过程中,该行的颜色和该行的数据怎么保持同步?具体的步骤是怎么样的?我找到了几个类似的例子,但是很复杂,我研究了一个礼拜天还是没有什么进展。一个字“菜”,两个字“很菜”。小弟特来请教,请高手指点,谢谢!学习,关注……
解决方案 »
- MFC,在运算线程中用::PostMessage传给界面线程的消息是逐个被执行的么?
- MFC如何实现这个功能呢?
- 用串口类传送文件的问题
- 如何在MFC中修改窗口属性
- 请问如何使用msdn?
- 发到邮箱里的CSDN邮件期刊怎么阅读不了????!!!
- 哇!我有这么多分,散了!祝大家春节快乐!
- 对话框下如何使用不同的字体大小?
- "System.AccessViolationException"类型未经处理的异常在CTestDlg.exe....请问这是什么错啊?
- VS2013环境double lstd[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };语句在不同模式下效果不一致
- 请高手指点一下这个问题,多谢!
- 弱弱地问rtp/rtcp问题
ListCtrl 中有两个函数GetItemData 和SetItemData,你在第一次设置每行颜色时SetItemData,当改变行顺序时,调用GetItemData,判断颜色进行重画。
BEGIN_MESSAGE_MAP(CListCtrlDlg, CDialog)
...
ON_NOTIFY ( NM_CUSTOMDRAW, IDC_LISTCTRL, OnCustomdrawMyList )
...
END_MESSAGE_MAP()
请看http://www.codeproject.com/listctrl/highlightlistctrl.aspvoid CMyListCtrlView::OnCustomdrawMyList(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR ); // Take the default processing unless we set this to something else below.
*pResult = CDRF_DODEFAULT; //设置listctrl的格式,由格子等
pListCtrl.SetExtendedStyle(pListCtrl.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); //
// First thing - check the draw stage. If it's the control's prepaint
// stage, then tell Windows we want messages for every item.
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{
// This is the notification message for an item. We'll request
// notifications before each subitem's prepaint stage.
*pResult = CDRF_NOTIFYSUBITEMDRAW;
}
else if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
{
COLORREF clrNewTextColor, clrNewBkColor;
int nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec );
DWORD dwColorType = m_ctListCtrl.GetItemData(nItem);
switch(dwColorType)
{
case 1://方案一
clrNewTextColor = RGB(0,0,0); //Set the text to red
clrNewBkColor = RGB(240,240,240); //Set the bkgrnd color to blue
break;
case 2://方案2
clrNewTextColor = RGB(0,0,0); //Leave the text black
clrNewBkColor = RGB(255,255,255); //leave the bkgrnd color white
break;
} pLVCD->clrText = clrNewTextColor;
pLVCD->clrTextBk = clrNewBkColor;
// Tell Windows to paint the control itself.
*pResult = CDRF_DODEFAULT;
}
}
你在插入数据时要设置每行的显示方案
int nItem = m_ctListCtrl.GetItemCount();
m_ctListCtrl.InsertItem(nItem...);
//设置成方案1
m_ctListCtrl.SetItemData(nItem, (DWORD)1);
extern CComboBox* pmyComboBox;// Set the data of each item to be equal to its index.
for (int i=0;i < pmyComboBox->GetCount();i++)
{
pmyComboBox->SetItemData(i, i);
}