I am trying to customize Background color and font color of a ListView item using OnCustomDrawItem event. However, the border color of subitem is always the background color of ListView. Does anyone know how to fix this? Here is the code i am using:
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
lst: TListView;
i: integer;
f1, f2, c1, c2: TColor;
begin
if (TListView(Sender).ViewStyle = vsIcon) then
Exit;
lst := Sender as TListView;
lst.Canvas.Brush.Style := bsSolid;
i := lst.Items.Count;
if (i mod 2) <> 0 then
begin
c1 := clWhite;
c2 := $00F8F8F8;
f1 := clBlue;
f2 := clBlack;
end else
begin
c1 := $00F8F8F8;
c2 := clWhite;
f1 := clBlack;
f2 := clBlue;
end;
// Painting...
if (Item.Index mod 2) = 0 then
begin
lst.Canvas.Brush.Color := c2;
lst.Canvas.Font.Color := f2;
end else
begin
lst.Canvas.Brush.Color := c1;
lst.Canvas.Font.Color := f1;
end;
end;
EDIT:
There is a GAP between column of SubItems. This GAP is the color of ListView's background.
I use Delphi XE2 and OS: Windows 7 bit bit.
(Item.Index mod 2) = 0
byOdd(Item.Index)
(or the negation of the last statement). - Andreas Rejbrand