Henry Olive 5 Posted January 3, 2023 Good Day, My table looks like below (In a DBGrid) CODE ------- AAA AAA-AA AAA-AA-BB BBB BBB-BB BBB-BB-CC I want to make font color ClRed if the Value.Length <= 3 That is just AAA and BBB value's font.color should be red procedure TAccAccounts.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var Str : String; begin Str := DBGrid1.Columns[0].Field.Value; if Length(Str) <= 3 then DBGrid1.Columns[0].Font.Color := ClRed else DBGrid1.Columns[0].Font.Color := ClWindowText; Self.Canvas.FillRect(Rect); end; Eventhough Delphi makes AAA clRed but doesnt make BBB clRed it is still clBlack Thank You Share this post Link to post
Uwe Raabe 2057 Posted January 3, 2023 Have you tried using the debugger to inspect the actual content of Str in the problematic case? Share this post Link to post
Lajos Juhász 293 Posted January 3, 2023 In the event you should change the color of the font on canvas not the column. Share this post Link to post
programmerdelphi2k 237 Posted January 3, 2023 (edited) Quote sure what... this: procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState); begin if Field.AsString.trim.Length <= 3 then DBGrid1.Canvas.Font.Color := clRed else DBGrid1.Canvas.Font.Color := clBlue; DBGrid1.DefaultDrawColumnCell(Rect, 0, DBGrid1.Columns[0] , State); end; Edited January 3, 2023 by programmerdelphi2k Share this post Link to post
Henry Olive 5 Posted January 7, 2023 Sorry for late respond i was sick for couple of days Thank You so much Uwe, Lajos, Programmer Share this post Link to post