sexta-feira, 12 de setembro de 2008

Mudar a cor de dbgrid conforme o conteúdo

//muda a cor somente da célula
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (Column.Field.FieldName = 'Pago') then
begin
if table1.FieldByName('pago').AsString = 'sim' then
begin
dbgrid1.Canvas.Font.Color := clBlue;
dbgrid1.Canvas.Font.Style :=[fsBold];
dbgrid1.Canvas.FillRect(Rect);
dbgrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end
else
begin
dbgrid1.Canvas.Font.Color:= clRed;
dbgrid1.Canvas.FillRect(Rect);
dbgrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
end;
end;

//muda a cor de toda a linha
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
if table1.FieldByName('pago').AsString = 'sim' then
begin
dbgrid1.Canvas.Font.Color := clBlue;
dbgrid1.Canvas.Font.Style :=[fsBold];
dbgrid1.Canvas.FillRect(Rect);
dbgrid1.DefaultDrawDataCell(Rect,Field,State);
end
else
begin
dbgrid1.Canvas.Font.Color:= clRed;
dbgrid1.Canvas.FillRect(Rect);
dbgrid1.DefaultDrawDataCell(Rect,Field,State);
end;
end;

6 comentários:

thigus disse...

onde consigo o TFiled

Reibeiro Info disse...

na uses do form digita
DB;

Unknown disse...

Por favor quem é esse " table1 ", não consigo entender esse cara ai pois sou iniciante. obrigado e que DEUS os abençoe...

Rodrigo disse...

José, o table1 vc troca pelo nome da sua tabela. Digamos que vc está alterando o dbGrid de uma tabela chamada Pagamentos. Vc troca o table1 pelo PAGAMENTOS

Unknown disse...

12Estou tendo esse erro,
E2005 'TField' is not a type identifier.

erro em identificar o TField. o como eu resolvo isso?

Unknown disse...

12Estou tendo esse erro,
E2005 'TField' is not a type identifier.

erro em identificar o TField. o como eu resolvo isso?