mudar a fonte do dbgrid

Delphi

11/03/2004

alguem sabe como que eu posso fazer para alterar a fonte de somente um determindado item do dbgrid.

ex:

se variavel > valor entao
item.font.color := azul
senao
item.font.color := vermelho


Zumbi

Zumbi

Curtidas 0

Respostas

Freestyle

Freestyle

11/03/2004

Coloque a propriedade defaultdrawdata do dbgrid em FALSE;

No evento onDrawColumnCell do dbgrid coloque o código para mudar a cor do font do dbgrid e a chave do método para ´desenhar´ os dados.

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const
Rect: TRect;
DataCol: Integer;
Column: TColumn;
State: TGridDrawState);
begin
If Condição then Dbgrid1.Canvas.Font.Color:= clBlue // coloque aqui a cor desejada
Else Dbgrid1.Canvas.Font.Color:= clRed;
Dbgrid1.DefaultDrawDataCell(Rect, dbgrid1.columns[datacol].field, State);
end;


GOSTEI 0
Zumbi

Zumbi

11/03/2004

valeu pela ajuda..
para quem um dia ter essa duvida e resolver pesquisar no forum ai vai como que eu consegui:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if (Column.Field.FieldName = ´CAMPO_DA_TABELA´) then//coloque a coluna em que vc quer que mude a cor da celula.
  begin
     if  then // coloque aqui a condição para trocar a cor.
     begin
        DBGrid1.Canvas.Brush.Color:= clred;
        DBGrid1.Canvas.Font.Color:= clWindowText;
        DBGrid1.Canvas.FillRect(Rect);
        DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
     end;
  end;


valew pessoal..


GOSTEI 0
POSTAR