Peter Kiers
asked on
Question about a color rows in my own listview component
Dear Experts,
I have this to color the rows of a listview:
procedure TMainForm.PkListv1CustomDr awItem(Sen der: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if Odd(Item.Index) then
PkListv1.Canvas.Brush.Colo r := clGray
else
PkListv1.Canvas.Brush.Colo r := clWindow;
end;
I am making my own listview-component, can this code above
be build in the component itself, i guess i have to use the onpaint
event, but I have no clue how to start. Does someone has the
experience with that?
Greetings, Peter
I have this to color the rows of a listview:
procedure TMainForm.PkListv1CustomDr
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if Odd(Item.Index) then
PkListv1.Canvas.Brush.Colo
else
PkListv1.Canvas.Brush.Colo
end;
I am making my own listview-component, can this code above
be build in the component itself, i guess i have to use the onpaint
event, but I have no clue how to start. Does someone has the
experience with that?
Greetings, Peter
unit PkListView;
interface
uses
SysUtils, Classes, Controls, ComCtrls, Windows;
type
PkListv = class(TListView)
private
{ Private declarations }
protected
{ Protected declarations }
FHeaderHandle: HWND;
function GetHeaderHeight:Integer;
procedure SetHeaderHeight(h:Integer);
public
{ Public declarations }
constructor Create(AOwner: TComponent);
destructor Destroy();
published
{ Published declarations }
property HeaderHeight:Integer read GetHeaderHeight write SetHeaderHeight;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [PkListv]);
end;
{ PkListv }
const
LVM_FIRST = $1000;
LVM_GETHEADER = LVM_FIRST + 31;
constructor PkListv.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
destructor PkListv.Destroy;
begin
inherited;
end;
function PkListv.GetHeaderHeight: Integer;
Var
Rc:TRect;
begin
Result:=0;
FHeaderHandle:=SendMessage(Handle, LVM_GETHEADER, 0, 0);
If GetWindowRect(FHeaderHandle, rc)
Then Result := rc.Bottom - rc.Top
end;
procedure PkListv.SetHeaderHeight(h: Integer);
begin
FHeaderHandle:=SendMessage(Handle, LVM_GETHEADER, 0, 0);
SetWindowPos( FHeaderHandle, 0 , 0, 0, Width, h, 0 );
InvalidateRect(FHeaderHandle,nil,True);
end;
end.
ASKER
How do you do that?
How do you know that the customdrawitem has to be changed?
Peter
How do you know that the customdrawitem has to be changed?
Peter
ASKER
In order to test your code I have to put data in the rows of the listview:
How can I fill a line of text dynamicly?
procedure TMainForm.btnTESTClick(Sen der: TObject);
var
MyListv: PkListv;
MyListCol : TListColumn;
begin
MyListv:= PkListv.Create(Self);
MyListv.Parent := self;
MyListv.Align := alTop;
MyListv.Height := 300;
MyListv.ViewStyle := vsReport;
MyListv.GridLines := True;
MyListv.ColumnClick := False;
MyListv.SmallImages := ImageList1;
MyListv.HeaderHeight:=20;
MyListv.Items <========================= =========
MyListCol := MyListv.Columns.Add;
MyListCol.Alignment := taLeftJustify;
MyListCol.Width := 150;
MyListCol.Caption := 'Naam';
end;
How can I fill a line of text dynamicly?
procedure TMainForm.btnTESTClick(Sen
var
MyListv: PkListv;
MyListCol : TListColumn;
begin
MyListv:= PkListv.Create(Self);
MyListv.Parent := self;
MyListv.Align := alTop;
MyListv.Height := 300;
MyListv.ViewStyle := vsReport;
MyListv.GridLines := True;
MyListv.ColumnClick := False;
MyListv.SmallImages := ImageList1;
MyListv.HeaderHeight:=20;
MyListv.Items <=========================
MyListCol := MyListv.Columns.Add;
MyListCol.Alignment := taLeftJustify;
MyListCol.Width := 150;
MyListCol.Caption := 'Naam';
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks it works.
Peter
Peter
function TCustomListView.CustomDraw
Stage: TCustomDrawStage): Boolean;
begin
Result := True;
if (Stage = cdPrePaint) and Assigned(FOnCustomDrawItem
if Assigned(FOnAdvancedCustom
end;
Open in new window