Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to set a Textcolor in a CListCtrl

How to set a Textcolor in a CListCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi community, how can i set a Textcolor in a CListCtrl for each Item? In addiction from an Itemvalue i want to set a different Item's Textcolor! :confused: Any Idea? thanx break;

    P 1 Reply Last reply
    0
    • L Lost User

      Hi community, how can i set a Textcolor in a CListCtrl for each Item? In addiction from an Itemvalue i want to set a different Item's Textcolor! :confused: Any Idea? thanx break;

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      Use NM_CUSTOMDRAW. Sample for this code will be like this

      void MyDlg::OnCustomdrawList ( NMHDR* pNMHDR, LRESULT* pResult )
      {
      NMLVCUSTOMDRAW* pLVCD = reinterpret_cast( pNMHDR );

      \*pResult = 0;
      
      if ( CDDS\_PREPAINT == pLVCD->nmcd.dwDrawStage )
          {
          \*pResult = CDRF\_NOTIFYITEMDRAW;
          }
      else if ( CDDS\_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
          {
          \*pResult = CDRF\_NOTIFYSUBITEMDRAW;
          }
      else if ( (CDDS\_ITEMPREPAINT | CDDS\_SUBITEM) == pLVCD->nmcd.dwDrawStage )
          {
                   //this will get called for each column in list box
                   //you can deter mine column number by pLVCD->iSubItem
                   COLORREF crText, crBkgnd;
                   crText = RGB(0,255,100);
                   crBkgnd = RGB(255,32,11);
                   pLVCD->clrText = crText;
                   pLVCD->clrTextBk = crBkgnd;
                  \*pResult = CDRF\_DODEFAULT;
          }
      

      }

      A 1 Reply Last reply
      0
      • P prasad_som

        Use NM_CUSTOMDRAW. Sample for this code will be like this

        void MyDlg::OnCustomdrawList ( NMHDR* pNMHDR, LRESULT* pResult )
        {
        NMLVCUSTOMDRAW* pLVCD = reinterpret_cast( pNMHDR );

        \*pResult = 0;
        
        if ( CDDS\_PREPAINT == pLVCD->nmcd.dwDrawStage )
            {
            \*pResult = CDRF\_NOTIFYITEMDRAW;
            }
        else if ( CDDS\_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
            {
            \*pResult = CDRF\_NOTIFYSUBITEMDRAW;
            }
        else if ( (CDDS\_ITEMPREPAINT | CDDS\_SUBITEM) == pLVCD->nmcd.dwDrawStage )
            {
                     //this will get called for each column in list box
                     //you can deter mine column number by pLVCD->iSubItem
                     COLORREF crText, crBkgnd;
                     crText = RGB(0,255,100);
                     crBkgnd = RGB(255,32,11);
                     pLVCD->clrText = crText;
                     pLVCD->clrTextBk = crBkgnd;
                    \*pResult = CDRF\_DODEFAULT;
            }
        

        }

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Hi, thanx, i it helps! :) regards break;

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups