How to insert colored text in a ListView?

I have a listview with 3 coloumns. The first two columns are relevant, and the third is still empty. I want to know how can I insert colored text later in the third column? I do not want to color the entire row, only the third column with changing colors.

Thanks in advance!

Kampi

+4
source share
2 answers

@ Richard Harrison has the right idea to use NM_CUSTOMDRAW .

Instead of re-implementing the necessary functionality, though you should consider using one of the freely available CListView types.

Here is a project that I think will satisfy your needs.

0
source

You can do this with the CustomDraw handler, ref: MSDN Developing Custom Draw Controls in Visual C ++ .

It is basically quite simple (and MSDN is quite long), but it boils down to the following:

add one of them to the usual place:

  ON_NOTIFY_REFLECT (NM_CUSTOMDRAW, OnCustomDraw)

Then add this method to the class.

  void CMyListView :: OnCustomDraw (NMHDR * nmhdr, LRESULT * result)
 {
     LPNMLVCUSTOMDRAW vcd = (LPNMLVCUSTOMDRAW) nmhdr;

     switch (vcd-> nmcd.dwDrawStage)
     {
         case CDDS_PREPAINT:
         {
             * result = CDRF_NOTIFYITEMDRAW;
             break;
         }

         case CDDS_ITEMPREPAINT:
         {
             vcd-> clrText = RGB (255,0,255);  // change the color of the second row.
             * result = CDRF_NOTIFYSUBITEMDRAW;
             break;
         }
         default:
             * result = 0;
             break;
     }
     return
 }
+5
source

Source: https://habr.com/ru/post/1301599/


All Articles