Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

Draw a selection in a listview

Hi,

I have a listview on my form, with the the property OwnerDraw is True.
I want to draw a selection, just like the property RowSelect
(Brush = darkblue and white font)

This is what I got, but I don't get further than this:

procedure TMainForm.lstvFoodDBCustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
  if Item.Selected then
  begin
  Sender.Brush.Color := clNavy;
  end
  else
  Sender.Brush.Color := clWIndow;
end;

Who can help me?

P.
ASKER CERTIFIED SOLUTION
Avatar of Emmanuel PASQUIER
Emmanuel PASQUIER
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Peter Kiers

ASKER

Undeclared identifier 'min'

Uses Math;
The code is not correct as you can see in the image.
Naamloos.jpg
Note that it will not be pretty if columns are resized.
You can use this technique, it adds OnColumnResize events, and the bonus to invalidate the column drawings when resized - so they are redrawn properly without even needing to be told. It works well for me.

http://www.swissdelphicenter.ch/torry/showcode.php?id=1264
Well a you can see in the picture its not quit how I wanted it
Are you sure you did it right ? Check this :
*  DefaultDraw:=False;  (in custom draw event)
*  OwnerDraw := True

I have changed the colors to be sure that it is my custom drawing :
LVCustomDraw.gif
I tested it with Delphi 7, you seem to have a newer version (2007?), I'll test tomorrow with 2007.
It works fine. I had use the JvListview-component from JEDI VCL.
But now I have tried it on a listview and it works fine.

Greetings, Peter Kiers