• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 344
  • Last Modified:

Coloring dbgrid rows when it meets one or more condition

Related to my previous question.

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26977229.html

Is there a way to color certain coloumns a different color depending on the value of the field?

The first column is Doc_Type and I need to have it colored in 3 different colors depending the value eg: If value is Fax then Row is Red if value is Original = Green and if value is Copy = Yellow.
0
DigitalNam
Asked:
DigitalNam
  • 3
  • 2
1 Solution
 
jimyXCommented:
You are going to use the Canvas properties at the DBGridDrawColumnCell event of the DBGrid.
You may check this article which is going to answer many of your questions.
0
 
DigitalNamAuthor Commented:
Thanks JimyX. At the rate I am going today you are going to earn ALOT of points. Hehe
0
 
jimyXCommented:
Could you try this please:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
    DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  DBGrid1.Canvas.Brush.Color := clWhite;  // the default color

  if DB.FieldByName('Doc_Type').AsString = 'Fax' then //you can use uppercase() to handle case sensitivity, if required
    DBGrid1.Canvas.Brush.Color := clRed;
  if DB.FieldByName('Doc_Type').AsString = 'Original' then
    DBGrid1.Canvas.Brush.Color := clGreen;
  if DB.FieldByName('Doc_Type').AsString = 'Copy' then
    DBGrid1.Canvas.Brush.Color := clYellow;
  DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

Open in new window

0
 
jimyXCommented:
Am ready and cracking my fingers waiting  :)
0
 
DigitalNamAuthor Commented:
Get ready for the next question.. :-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now