Board index » delphi » Changing DBGrid attributes

Changing DBGrid attributes

Hello,

Does anybody knows how to change the font color and size of the selected

row in a DBGrid ??

Thank you

Diego Irrazabal

 

Re:Changing DBGrid attributes


Quote
"Diego Irrazabal" <diego_irraza...@hotmail.com> wrote in message

news:3BAFAB17.E634156F@hotmail.com...

Quote

> Does anybody knows how to change the font color and size of the selected
> row in a DBGrid ??

Use the DBGrid's OnDrawColumnCell event. Here's an example:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if Column.FieldName = 'ThatField' then begin
    DBGrid1.Canvas.Font.Color := clWhite;
    if Column.Field.AsInteger > 10 then
      DBGrid1.Canvas.Brush.Color := clRed
    else
      DBGrid1.Canvas.Brush.Color := clGreen
  end else begin
    DBGrid1.Canvas.Brush.Color := clWindow;
    DBGrid1.Canvas.Font.Color := clWindowText;
  end;
  DBGrid1.DefaultDrawColumnCell(Rect, DataCOl, Column, State);
end;

--
Wayne Niddery (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
"Some see private enterprise as a predatory target to be shot, others as a
cow to be milked, but few are those who see it as a sturdy horse pulling the
wagon." - Winston Churchill

Other Threads