Author Topic: CListCtrl different colors for each row  (Read 1232 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
CListCtrl different colors for each row
« on: June 14, 2011, 03:26:16 pm »
To have CListCtrl different colors for each row, you need to implement NM_CUSTOMDRAW message.


ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST1,  &CMyDialog::OnNMCustomdrawList1)


void CMyDialog::OnNMCustomdrawList1(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 = RGB(0,0,0);
        if ((pLVCD->nmcd.dwItemSpec %2) == 0) // even lines
            crText = RGB(255,0,0);
        pLVCD->clrText = crText;
        *pResult = CDRF_DODEFAULT;
    }
}


For more details, visit us at http://www.softwareandfinance.com


 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1