• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 730
  • Last Modified:

TwwDBGrid Cell Color

Sutto Code Example;
  Delphi 7.0 InfoPower 4
  Note: FieldA is not visible in the grid, of course that should not matter.
  BothFields are in the same row and dataset. Simple right?
  with wwDBGrid1 do begin

    if ( FieldB.Text =  'T') then begin
      FieldA.CellColor = clBlue;
      FieldA.CellFont.Color = clBlack;
    else begin
      FieldA.CellColor = clYellow;
      FieldA.CellFont.Color = clRed;


Greg Rowland
Greg Rowland
2 Solutions
Greg RowlandSoftware Designer, SysDBA, WebMaster OwnerAuthor Commented:
Unless anyone has a better idea, these works!

procedure TAnyUnit.wwDBGrid1CalcCellColors(Sender: TObject;
  Field: TField; State: TGridDrawState; Highlight: Boolean; AFont: TFont;
  ABrush: TBrush);

   with wwDBGrid1 do begin

    if (Field.FieldName = 'FieldA') then begin
      if ( FieldByName( 'FieldB').Value = 'T') then begin
        Canvas.Brush.Color := clBlue;
        Canvas.Font.Color := clYellow;

      end else begin
        Canvas.Brush.Color := clYellow;
        Canvas.Font.Color := clRed;

Sinisa VukCommented:
This is ok - even on a standard dbgrid - but using similar event.
My suggestion is to check Highlight value before ...
if not Highlight then
  //your code: with ...

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now