Board index » delphi » DbGrid font colour change in individual cells

DbGrid font colour change in individual cells

Hi.. hopefully a simple question, but here goes

I'm using a dbgrid and would like to highlight all negative values by
changing the font colour of these items to red.

Anyone able to assist with this ?

Thanks in advance

Dave

 

Re:DbGrid font colour change in individual cells


Use the OnDrawColumnCell event of the DbGrid, see Delphi's help for more
information

Quote
DA Brookes wrote:
> Hi.. hopefully a simple question, but here goes

> I'm using a dbgrid and would like to highlight all negative values by
> changing the font colour of these items to red.

> Anyone able to assist with this ?

> Thanks in advance

> Dave

--
Guillermo Casta?o Acevedo <SIRIO>
Guiller...@GrupoMillennium.com
Guillermo...@Hotmail.com
WWW: http://www.GrupoMillennium.com (Gerente de Sistemas)
ICQ # 33844513
Systems and Computers Engineer

Re:DbGrid font colour change in individual cells


Quote
>DA Brookes wrote:

> I'm using a dbgrid and would like to highlight all negative values by
> changing the font colour of these items to red.

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:
TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if Table1.FieldByName('Gain').AsInteger < 0 then  
    begin
      DBGrid1.Canvas.Font.Color := clRed;       { Font color }
      DBGrid1.Canvas.Brush.Color := clWhite;    { Cell color }
    end;
  DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State)
________
Andreas
Delphi 5.01 Pro, NT4 Sp6a
Direct replies mailto:paw...@gmx.net

Other Threads