ListView Font Color in Column 0

JBALES
JBALES used Ask the Experts™
on
When I use the code below, the whole row is colored instead of just Column 0... what am I doing wrong?
procedure TfrmMain.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
  // Process column 0 here

  if (StrToInt(ListView1.Items[0].Caption)) > 0 then
    ListView1.Canvas.Font.Color := clGreen
  else
    ListView1.Canvas.Font.Color := clRed;
end;

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ferruccio AccalaiSenior developer, analyst and customer assistance
Commented:
use CustomDrawSubitems for the subithems

procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView; Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
  ListView1.Canvas.Font.Color := clGreen
end;

procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
  ListView1.Canvas.Font.Color := clRed;
end;
Top Expert 2010
Commented:
add handler to OnCustomDrawSubItem event:

procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
  ListView1.Canvas.Font.Color := clBlack;
end;

Author

Commented:
Thank you
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Ferruccio AccalaiSenior developer, analyst and customer assistance

Commented:
Just copying or repeating a comment deserves an assisted point split?
Wow, I'm just getting old...
Top Expert 2010

Commented:
>> Just copying

Thanks for that. You're very kind, Ferruccio68
Ferruccio AccalaiSenior developer, analyst and customer assistance

Commented:
I apologize, wasn't about you aflarin. Anyway you must admit that your answer was exactly like mine. I repeat, nothing with you aflarin.

Author

Commented:
Sorry I am new

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial