DigitalNam
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;
Am ready and cracking my fingers waiting :)
ASKER
Get ready for the next question.. :-)
ASKER