Jump to content
Henry Olive

DBGrid1.Columns[1].Font.Color

Recommended Posts

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

Have you tried using the debugger to inspect the actual content of Str in the problematic case?

Share this post


Link to post
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;

image.png.05bc7ef713d3cb118188b697ea3ff7f3.png

Edited by programmerdelphi2k

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×