Board index » delphi » color a cell in a DBGRID???

color a cell in a DBGRID???

hi,

I need to color a cell in a DBGRID when the DBGRID is displayed.  Basically, I
want to color a date if the item is overdue.  I can color the entire row but I
can't figure out how to color the cell.

any help will be appreciated.

thanks in advance.
tony

 

Re:color a cell in a DBGRID???


Set DefaultDraw to False and use the following OnDrawColumnCell event:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  with Sender as TDBGrid do
  begin
    if (Column.FieldName = 'OrderDate') and (Column.Field.AsDateTime < Now)
then
    begin
      Canvas.Brush.Color := clRed;
      Canvas.Font.Color := clWhite;
    end;
    DefaultDrawColumnCell(Rect, DataCol, Column, State);
  end;
end;

"TTsangarak" <ttsanga...@aol.comnojunk> schreef in bericht
news:20010110074519.14551.00001011@ng-fj1.aol.com...

Quote
> hi,

> I need to color a cell in a DBGRID when the DBGRID is displayed.
Basically, I
> want to color a date if the item is overdue.  I can color the entire row
but I
> can't figure out how to color the cell.

> any help will be appreciated.

> thanks in advance.
> tony

Other Threads