Cores em uma DBGrid
Galera, como posso colocar cores em determinadas linhas de uma dbGrid, baseado em seu conteúdo?
[]´s
Duilton
[]´s
Duilton
Duilton
Curtidas 0
Respostas
Buosinet
11/08/2003
Vc deve usar o evento OnDrawColumnCell da DBGrid. Veja o exemplo abaixo, que pinta a fonte de vermelho caso a data seja superior a 01/01/94:
procedure TForm1.DBGrid1DrawColumnCell1(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (Column.FieldName = ´LastInvoiceDate´) then
with DBGrid1.Canvas do begin
if Table1LastInvoiceDate.Value >= EncodeDate(1994,1,1) then
Font.Color := clNavy
else
Font.Color := clRed;
end;
DBGrid1.DefaultDrawDataCell(Rect,Column.Field,State);
end;
procedure TForm1.DBGrid1DrawColumnCell1(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (Column.FieldName = ´LastInvoiceDate´) then
with DBGrid1.Canvas do begin
if Table1LastInvoiceDate.Value >= EncodeDate(1994,1,1) then
Font.Color := clNavy
else
Font.Color := clRed;
end;
DBGrid1.DefaultDrawDataCell(Rect,Column.Field,State);
end;
GOSTEI 0