Cant' color columns in ListView
Original Reporter info from Mantis: bonmario @bonmario
-
Reporter name: Mario Bonati
Original Reporter info from Mantis: bonmario @bonmario
- Reporter name: Mario Bonati
Description:
i use this code in Delphi to colorate with different colors columns of a ListView, but with Lazarus they does nothing:
procedure TForm1.SetLVColumnColour(ColIdx: Integer);
// Sets the list view brush colour for the column
const
// The colours for each list view column
cRainbow: array[0..3] of TColor = (
$FFCCCC, $CCFFCC, $CCCCFF, $CCFFFF
);
begin
ListView1.Canvas.Brush.Color := cRainBow[ColIdx];
end;
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState;
var DefaultDraw: Boolean);
// Draw the "Caption" column
begin
// Set the colour for column 0
SetLVColumnColour(0);
end;
procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
// Draw the sub item columns
begin
// Check if SubItem is 0 and exit (Delphi 4 calls this event
// with SubItem = 0, while Delphi 7 starts with SubItem = 1
if SubItem = 0 then Exit;
// We set the background colour to the colour required for
// the column per the SubItem parameter
SetLVColumnColour(SubItem);
end;
Same problem whit these that i use for colorate lines:
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState;
var DefaultDraw: Boolean);
const
cStripe = $CCFFCC; // colour of alternate list items
begin
if Odd(Item.Index) then
// odd list items have green background
ListView1.Canvas.Brush.Color := cStripe
else
// even list items have window colour background
ListView1.Canvas.Brush.Color := clWindow;
end;
Mantis conversion info:
- Mantis ID: 9255
- OS: WinXP
- OS Build: SP2
- Platform: Win32
- Version: 0.9.23 (SVN)
- Fixed in version: 0.9.27 (SVN)
- Fixed in revision: 20273 (#b6cec7a9)
- Target version: 1.4