unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls;
type
TForm1 =
class(TForm)
ListView1: TListView;
procedure ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState;
var DefaultDraw: Boolean);
procedure ListView1CustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
private
{ Private declarations }
procedure SetLVColumnColour( ListView: TCustomListView; Column: Integer );
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
// mit dieser methode ändern wir die Hintergrund-Farbe
// Als eingabe eine Listview und die Spalte angeben
procedure TForm1.SetLVColumnColour( ListView: TCustomListView; Column: Integer );
const
cColors:
array[0..2]
of TColor = ( clWindow, clGreen, clYellow );
begin
ListView.Canvas.Brush.Color := cColors[Column];
end;
// Hier wird die Hauptspalte eingefärbt
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState;
var DefaultDraw: Boolean);
begin
SetLVColumnColour( Sender, 0 );
end;
// Hier werden Sub-Spalten eingefärbt
procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
begin
if SubItem = 0
then Exit;
SetLVColumnColour( Sender, SubItem );
end;
end.