Solved

Color rows of a Listview

Posted on 2010-09-13
2
264 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 89
Printing problem 2 80
Delphi 2 47
how to change, disabled button color FMX ? 1 14
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now