Solved

How do Color font and Row Background in listview

Posted on 2010-09-04
5
423 Views
Last Modified: 2012-06-21
Hi, I'd like to be able to Color the font and Background of a row in listview when I click on the item, and only that item is colored.

when I select another than one is colored and the rest are not.

how is this possible?
0
Comment
Question by:eNarc
  • 3
5 Comments
 
LVL 13

Expert Comment

by:aflarin
ID: 33604426
Set RowSelect property of ListView to true
0
 
LVL 5

Author Comment

by:eNarc
ID: 33606367
that will color the selected row?
0
 
LVL 25

Expert Comment

by:epasquier
ID: 33607721
You will have to code an owner draw event
0
 
LVL 25

Expert Comment

by:epasquier
ID: 33607744
I mean, if you want to change the colors and not use the default ones, otherwise, aflarin is right and RowSelect property is enough.
0
 
LVL 25

Accepted Solution

by:
epasquier earned 500 total points
ID: 33674664
Here is a sample with OwnerDraw property set to True and a CustomDrawItem event. From this you can customize whatever you wish about the items and subitems drawing (colors, positions...)
procedure TForm1.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 := clRed;
     Font.Color:= clWhite;
    end else
    begin
     if (Item.Index And 1)=1
      Then Brush.Color := clGray
      Else Brush.Color := clWhite;
     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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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