Fórum Colorir no DBGrid #328476
02/09/2006
0
Há algum tempo consegui aqui uma dica para colorir os texto das linhas do DBGrid, mediante o atendimento de uma condição. Na época eu utilizava o Delphi 3. E hoje trabalhando com o Delphi 7 ao utilizar a referida dica, o Delphi mostra um erro no meio do código em cima do comando ´PSChar(S)´.
O código é o seguinte:
procedure TFormVendas_.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
var
S: String;
R: TRect;
begin
if (dm_.QryVendasVencimento.Value = StrToDateTime(DateToStr(Now+1)))then
begin
with DBGrid1.Canvas do
begin
Font.Color := clGreen;
FillRect(Rect);
S := Column.Field.AsString;
R := Rect;
DrawText(Handle, PChar(S), Length(S), R, DT_LEFT or DT_LEFT);
end;
end;
if (dm_.QryVendasVencimento.Value < StrToDateTime(DateToStr(Now)))then
begin
with DBGrid1.Canvas do
begin
Font.Color := clRed;
FillRect(Rect);
S := Column.Field.AsString;
R := Rect;
DrawText(Handle, PChar(S), Length(S), R, DT_LEFT or DT_LEFT);
end;
end;
if (dm_.QryVendasVencimento.Value = StrToDateTime(DateToStr(Now)))then
begin
with DBGrid1.Canvas do
begin
Font.Color := clBlue;
FillRect(Rect);
S := Column.Field.AsString;
R := Rect;
DrawText(Handle, [color=red:df2445ec8f]PChar(S), [/color:df2445ec8f]Length(S), R, DT_LEFT or DT_LEFT);
end;
end;
end;
Se alguém puder me ajudar, ficarei muito grato.
Antecipadamente agradeço a ajuda de todos.
O código é o seguinte:
procedure TFormVendas_.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
var
S: String;
R: TRect;
begin
if (dm_.QryVendasVencimento.Value = StrToDateTime(DateToStr(Now+1)))then
begin
with DBGrid1.Canvas do
begin
Font.Color := clGreen;
FillRect(Rect);
S := Column.Field.AsString;
R := Rect;
DrawText(Handle, PChar(S), Length(S), R, DT_LEFT or DT_LEFT);
end;
end;
if (dm_.QryVendasVencimento.Value < StrToDateTime(DateToStr(Now)))then
begin
with DBGrid1.Canvas do
begin
Font.Color := clRed;
FillRect(Rect);
S := Column.Field.AsString;
R := Rect;
DrawText(Handle, PChar(S), Length(S), R, DT_LEFT or DT_LEFT);
end;
end;
if (dm_.QryVendasVencimento.Value = StrToDateTime(DateToStr(Now)))then
begin
with DBGrid1.Canvas do
begin
Font.Color := clBlue;
FillRect(Rect);
S := Column.Field.AsString;
R := Rect;
DrawText(Handle, [color=red:df2445ec8f]PChar(S), [/color:df2445ec8f]Length(S), R, DT_LEFT or DT_LEFT);
end;
end;
end;
Se alguém puder me ajudar, ficarei muito grato.
Antecipadamente agradeço a ajuda de todos.
Pro-luck
Curtir tópico
+ 0
Responder
Posts
02/09/2006
Raserafim
o DrawText pode ser usado, mas é uma API do Windows e o delphi tem uma rotina para ser usada ao pintar uma grid: DefaultDrawDataCell, que colocará o texto com a mesma formatação do campo field.
tente isto:
tente isto:
TDBGrid(Sender).Canvas.Brush.Color := CorIgual TDBGrid(Sender).Canvas.FillRect(Rect); TDBGrid(Sender).DefaultDrawDataCell(Rect, Column.Field, State);
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)