Link to home
Start Free TrialLog in
Avatar of DigitalNam
DigitalNamFlag for Namibia

asked on

Coloring dbgrid rows when it meets one or more condition

Related to my previous question.

https://www.experts-exchange.com/questions/26977229/MySQL-query-help.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.
ASKER CERTIFIED SOLUTION
Avatar of jimyX
jimyX

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DigitalNam

ASKER

Thanks JimyX. At the rate I am going today you are going to earn ALOT of points. Hehe
Avatar of jimyX
jimyX

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

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