uses
CommCtrl;
const
LVHighliterColor: TColor = clAqua;
LVHighliterColorOnFocused: TColor = clBlue;
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState;
var DefaultDraw: Boolean);
var
ColumnRect: TRect;
TextRect: TRect;
Drawstate: Cardinal;
SubitemIndex: Integer;
begin
Drawstate := 0;
DefaultDraw := False;
if TListView(Sender).ViewStyle = vsReport
then
begin
with (sender
as TListView)
do
begin
if (Item.Selected)
then
begin
if (Sender.Focused)
then
begin
Canvas.Pen.Color := LVHighliterColorOnFocused;
Canvas.Brush.Color := LVHighliterColorOnFocused;
end
else
begin
Canvas.Pen.Color := LVHighliterColor;
Canvas.Brush.Color := LVHighliterColor;
end;
end
else
begin
Canvas.Pen.Color := clWhite;
Canvas.Brush.Color := clWhite;
end;
ListView_GetItemRect(
Handle, Item.
Index, ColumnRect, LVIR_BOUNDS);
Canvas.Rectangle(ColumnRect);
ListView_GetItemRect(
Handle, Item.
Index, TextRect, LVIR_LABEL);
DrawText(Canvas.Handle, Pchar(Item.Caption), Length(Item.Caption),
TextRect, Drawstate);
for SubitemIndex := 1
to Columns.Count - 1
do
begin
ListView_GetSubItemRect(
Handle, Item.
Index, SubitemIndex, LVir_Label, @textrect);
DrawText(Canvas.Handle, Pchar(Item.SubItems[SubitemIndex - 1]),
Length(Item.SubItems[SubitemIndex - 1]),
TextRect, Drawstate);
end;
end;
end;
end;