Fórum Erro ao mudar com em um DBGrid após consulta #206467
14/01/2004
0
Galera,
Após realizar uma pesquisa em uma tabela Interbase (EMPRESAS), tento diferir a cor dos registros de acordo com o campo SITU, que pode ser B, R ou P.
Ocorre que ao fazer isto, o DBGrid apresenta apenas o primeiro registro, repetido várias vezes. Quando retiro o código de mudança de cor, tudo funciona perfeitamete! Se alguém puder me dar um help, ficarei muito agradecido!
Código da pesquisa:
Código da Mudança de Cores:
Abraços,
Após realizar uma pesquisa em uma tabela Interbase (EMPRESAS), tento diferir a cor dos registros de acordo com o campo SITU, que pode ser B, R ou P.
Ocorre que ao fazer isto, o DBGrid apresenta apenas o primeiro registro, repetido várias vezes. Quando retiro o código de mudança de cor, tudo funciona perfeitamete! Se alguém puder me dar um help, ficarei muito agradecido!
Código da pesquisa:
procedure TFrmBusca.BitBtn1Click(Sender: TObject); begin With DmEmpresas.QryBusca do Begin Close; Sql.Clear; Sql.Add(´Select * from empresas where ID=´+Quotedstr(EdtID_RelFisico.Text)+´ or ID_rel=´+Quotedstr(EdtID_RelFisico.Text)+´ order by codigo´); Open; end; FrmPrincipal.DBGrid2.Visible:=True; FrmPrincipal.PageControl1.ActivePageIndex:=1; Close; end;
Código da Mudança de Cores:
procedure TFrmPrincipal.DBGrid2DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin If DmEmpresas.Qrybusca.FieldByName(´Situ´).Asstring = ´B´ then begin DBGrid2.Canvas.Font.Color:=ClTeal; end else If DmEmpresas.Qrybusca.FieldByName(´Situ´).Asstring = ´R´ then begin DBGrid2.Canvas.Font.Color:=ClPurple; end else If DmEmpresas.Qrybusca.FieldByName(´Situ´).Asstring = ´P´ then begin DBGrid2.Canvas.Font.Color:=ClMaroon; end; DbGrid2.DefaultDrawDataCell(Rect, DbGrid1.Columns[datacol].field, State); end;
Abraços,
Pedro Bugim
Curtir tópico
+ 0
Responder
Posts
14/01/2004
Motta
eu faço assim é funciona
procedure TfrmFicha.dbgFinanceiroDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
procedure MudaCor (Fundo,Fonte: TColor);
begin
with dbgFinanceiro.Canvas do
begin
Brush.Color := Fundo;
Font.Color := Fonte;
FillRect(Rect);
TextOut(Rect.Left,Rect.Top,Column.Field.DisplayText);
end;
end;
begin
inherited;
With dbgFinanceiro.Canvas do
begin
if ((dtmCallCenter.qryDebitosIND_SITUACAO.AsFloat = 1) and
(dtmCallCenter.qryDebitosDT_VENCIMENTO.AsDateTime <= gLimiteAtraso)) then
MudaCor(clInfoBk,ClRed);
if dtmCallCenter.qryDebitosSITUACAO.IsNull then
MudaCor(clInfoBk,clGreen);
//Não esqueça de colocar a opção dgRowSelect como True na options do DBGrid.
// Inverte a cor da celula focada
if gdFocused in State then
Mudacor(Font.Color,Brush.Color);
end;
end;
procedure TfrmFicha.dbgFinanceiroDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
procedure MudaCor (Fundo,Fonte: TColor);
begin
with dbgFinanceiro.Canvas do
begin
Brush.Color := Fundo;
Font.Color := Fonte;
FillRect(Rect);
TextOut(Rect.Left,Rect.Top,Column.Field.DisplayText);
end;
end;
begin
inherited;
With dbgFinanceiro.Canvas do
begin
if ((dtmCallCenter.qryDebitosIND_SITUACAO.AsFloat = 1) and
(dtmCallCenter.qryDebitosDT_VENCIMENTO.AsDateTime <= gLimiteAtraso)) then
MudaCor(clInfoBk,ClRed);
if dtmCallCenter.qryDebitosSITUACAO.IsNull then
MudaCor(clInfoBk,clGreen);
//Não esqueça de colocar a opção dgRowSelect como True na options do DBGrid.
// Inverte a cor da celula focada
if gdFocused in State then
Mudacor(Font.Color,Brush.Color);
end;
end;
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)