I'd like to show a TDBGrid with different color rows. The color of the row would be mased on the value of a field in the dataset. If this is not possible, I'd like to try the same effect with the font color.
Apparently there is a way to achieve this with "OnDrawColumnCell" but I don't know how to put the code together to make it work.
Any help on using this feature to set a font color?
I tried:
------------------------------------------------------------
if table1.FieldByName('TrueFalse').AsBoolean = True then
DBGrid1.Canvas.Font.Color := clRed;
------------------------------------------------------------
I know I missed something but have no idea what it is.
TealWren is on the right track... Try this in the OnDrawDataCell event:
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
with DBGrid1.Canvas do
begin
FillRect(Rect);
if (Field.FieldName = 'TrueFalse') and (Field.AsBoolean = True) then
Font.Color := clRed
else
Font.Color := clBlack;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.