[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

is there anyway to color a selected listview item row in listview

Posted on 2010-01-06
4
Medium Priority
?
504 Views
Last Modified: 2012-05-08
~Hi, I'd like to be able to color a listview row.

like if I wanted item row 10, I've like that row being colored red.

then I'd like 17 colored green

and then all the rest colored blue.

is there anyway I can do this?
0
Comment
Question by:eNarc
4 Comments
 
LVL 7

Assisted Solution

by:twinsoft
twinsoft earned 400 total points
ID: 26195800
Hi, yes it is possible by using the OnCustomDrawItem

procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
 if (check some value) then
  Sender.Canvas.Font.Color := clRed;
end;
0
 
LVL 5

Author Comment

by:eNarc
ID: 26197238
hi i tried that and it makes all the color red, just needed the one item being red.
0
 
LVL 2

Accepted Solution

by:
gurkal earned 1600 total points
ID: 26197560
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
     if Item.Index=10 then
        Sender.Canvas.Font.Color:=clRed
     else
     if Item.Index=17 then
        Sender.Canvas.Font.Color:=clGreen
     else
        Sender.Canvas.Font.Color:=clBlue;
end;
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 26198237
there is probably some better criteria you have than the rownumber ?

i had some listviews where a warning icon was shown
and the line was a different color
procedure TfrmInventory.lvStockAdvancedCustomDrawItem(
  Sender: TCustomListView; Item: TListItem; State: TCustomDrawState;
  Stage: TCustomDrawStage; var DefaultDraw: Boolean);
begin
  if Item.ImageIndex = 0 then 
  begin
    Sender.Canvas.Font.Color := ClRed;
    Sender.Canvas.Font.Style := [fsBold];
  end;
end;

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month19 days, 21 hours left to enroll

872 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