Solved

Color rows of a Listview

Posted on 2010-09-13
2
267 Views
Last Modified: 2012-06-22
Hi,

I want to color the rows like this:

if odd(item.Index) then
Sender.Brush.Color := clSilver
 else
 Sender.Brush.Color := clWIndow;

But I have allready code in the ListView1CustomDrawItem.
Where should I implement it?

Greetings, Peter Kiers
procedure TMainForm.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
Var
 R:TRect;
 i,NC:integer;
 TotWidth:Integer;
begin
 DefaultDraw:=False;
 With Sender.Canvas do
  begin
   if Item.Selected then
    begin
     Brush.Color := clNavy;
     Font.Color:= clWhite;
    end else
    begin
     Brush.Color := clWIndow;
     Font.Color:= clBlack;
    end;
   FillRect(Item.DisplayRect(drBounds));
   R:=Item.DisplayRect(drLabel);
   TextRect(R,R.Left,R.Top,Item.Caption);
   NC:=Min(Item.SubItems.Count+1,TListView(Sender).Columns.Count);
   if NC<2 Then Exit;
   TotWidth:=Sender.Column[0].Width;
   for i:=1 to NC-1 do
    begin
     TextOut(R.Left+TotWidth,R.Top,Item.SubItems[i-1]);
     TotWidth:=TotWidth+Sender.Column[i].Width;
    end;
  end;
end;

Open in new window

0
Comment
Question by:peterkiers
  • 2
2 Comments
 
LVL 25

Expert Comment

by:epasquier
ID: 33665592

...
   if Item.Selected then
    begin
     Brush.Color := clRed;
     Font.Color:= clWhite;
    end else
    begin
     if (Item.Index And 1)=1         // Add a test for index is Odd here
      Then Brush.Color := clCream
      Else Brush.Color := clWhite;
     Font.Color:= clBlack;
    end;
...

Open in new window

0
 
LVL 25

Accepted Solution

by:
epasquier earned 500 total points
ID: 33665631
Ok, I could have used the Odd() function instead of that binary test for first bit ... Old habits die hard
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
code issue 8 177
Delphi: how to implement a User Shortcut mapper? 1 132
tidtcpserver connection lost handle 2 109
Delphi problems to abort a printjob 9 34
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question