c++listviewc++builderc++builder-xe5

ListView column shading bug


I want to add a color fill for selected column.

Drawing items I do in ListView1CustomDrawItem handler:

Sender->Canvas->Brush->Color = RGB(200, 200, 255);

   if(Item->Selected)
   {
   Sender->Canvas->Brush->Color = (Sender->Focused() ? clBlue : clRed);
   }

Sender->Canvas->Lock();
Sender->Canvas->FillRect(Item->DisplayRect(drBounds));
Sender->Canvas->TextOut(Item->DisplayRect(drLabel).Left, Item->DisplayRect(drLabel).Top + 1, Item->Caption);
Sender->Canvas->Unlock();
DefaultDraw = false;

And if I understand correctly, drawing the selected column I should do in the ListView1CustomDraw handler:

TRect rect;
rect = ARect;
rect.Right = Sender->Column[0]->Width;

Sender->Canvas->Brush->Color = RGB(245, 245, 245);


Sender->Canvas->Lock();
Sender->Canvas->FillRect(rect);
Sender->Canvas->Unlock();

And the result is:

http://i63.fastpic.ru/big/2014/1120/ba/e5b6d30eb9e05bbe3661aed295c28aba.jpg

It can also be seen on the video: http://youtu.be/XGXpWCUtGbU

As you can see, when I move (do not click) the cursor over the items, they are redrawn incorrectly. But the items must be drawn over the column colored rectangle. How can I fix this?


Solution

  • You need to handle the OnCustomDrawSubItem event as well. The OnCustomDrawItem event only applies to the first column.