I am using MFC function OnCustomDraw to change the text color of a row. But instead of specific row all the rows in list control gets red color. I have added condition also to check the text. In my listCtrl 7th column has passport details like "Yes" and "No". So if someone has "No" passport then only that row text should be red. Please help me on this. I am using below code.
void CMyListClass::OnCustomdrawMyList(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
*pResult = CDRF_DODEFAULT;
if (CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage)
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if (CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage)
{
COLORREF crText;
int nCol = 6;
CString m_SearchThisItemText = _T("No");
for (int i = 0; i < m_list.GetItemCount(); ++i)
{
CString szText = m_list.GetItemText(i, nCol);
if (szText == m_SearchThisItemText)
{
crText = RGB(255, 0, 0);
break;
}
}
pLVCD->clrText = crText;
*pResult = CDRF_DODEFAULT;
}
}
I tried to fetch the subitem coloring but no success.
You have to ask for the
CDRF_NOTIFYSUBITEMDRAWand have to check for stateCDDS_ITEMPREPAINT | CDDS_SUBITEMThe code might be easier with a switch/case.
See sample here https://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=24114