Como saber o foco de uma célula no DBGrid??
E aí pessoal!
Como posso saber qual a célula está em foco no DBGrid??
Pois o DBGrid está colorido mas eu quero que quando eu estiver focando ele volte ao normal ou altere a cor da fonte só quando estiver focado.
Se alguém souber por favor responda urgente!
Muito obrigado!
Como posso saber qual a célula está em foco no DBGrid??
Pois o DBGrid está colorido mas eu quero que quando eu estiver focando ele volte ao normal ou altere a cor da fonte só quando estiver focado.
Se alguém souber por favor responda urgente!
Muito obrigado!
Jowjow
Curtidas 0
Respostas
Silviogs
05/04/2004
Lá vai.
DBGrid1.SetFocus;
DBGrid1.SelectedIndex := 0;
DBGrid1.SelectedField.Name :=´Produto´;
Atenciosamente,
Silvio Guedes.
silvioguedespb@hotmail.com
Consulte esta rotina abaixo para voce ter controle de dgitacao no DBGRID.
procedure TFmCadPedidos.DBGrid1KeyPress(Sender: TObject; var Key: Char);
var
mtexto : string;
i ,prazoped : integer;
mtexto1, mtexto2, mtexto3 : string;
begin
prazoped := 0 ;
if Key = #13 then begin
if not (ActiveControl is TDBGrid) then begin
Key := 0;
Perform(WM_NEXTDLGCTL, 0, 0);
end
else
if (DBGrid1.SelectedIndex = 0) then begin
if DbGrid1.SelectedField.AsString = ´´ then
PesqProduto(13,true)
else
PesqProduto(13,false)
end
else
if DBGrid1.SelectedIndex = 1 then begin
DataModule1.ADOQryPedidoItemDescProd.Value := DataModule1.ADOQryProdutosNome.Value;
DBGrid1.SelectedIndex := 4;
end
else
if DBGrid1.SelectedIndex = 4 then begin
if DataModule1.ADOQryPedidoItemQuantidade.Value = 0 then begin
messagedlg(´A quantidtidade digitada é zero, favo digite uma quantidade válida!´,mterror,[mbOk],0);
DBGrid1.SelectedIndex := 4;
end
else
if DataModule1.ADOQryPedidoItemPrecovenda.Value <> 0.00 then
DataModule1.ADOQryPedidoItemTotal.Value := DataModule1.ADOQryPedidoItemQuantidade.Value * DataModule1.ADOQryPedidoItemPrecovenda.Value;
DBGrid1.SelectedIndex := 5;
PopupMenu1.Items.Clear;
DataModule1.ADOQryConsulta.Close;
DataModule1.ADOQryConsulta.SQL.Clear;
DataModule1.ADOQryConsulta.SQL.Add(´select clientepreco.preco,formapag.descricao,formapag.prazomedio, ClientePreco.Quantidademinima,Clientepreco.prazo,Clientepreco.promocao, produtos.preço1 from clientepreco ´+
´inner join formapag on ´+
´formapag.codigo=clientepreco.prazo ´+
´inner join produtos on ´+
´produtos.código=´+DataModule1.ADOQryPedidoItemProduto.Text+
´ where cliente=´+QuotedStr(DataModule1.ADOQryPedidoCliente.Text)+
´ and produto=´+DataModule1.ADOQryPedidoItemProduto.Text+
´ and quantidademinima <= ´+QuotedStr(DataModule1.ADOQryPedidoItemQuantidade.Text)+
´ and formapag.prazomedio > 0 ´+
´order by preco´);
DataModule1.ADOQryConsulta.Open;
DataModule1.ADOQryConsulta.First;
for i := 1 to DataModule1.ADOQryConsulta.RecordCount do begin
MenuItem := TMenuItem.Create(nil);
mtexto1 := FormatFloat(´#,00.00´,DataModule1.ADOQryConsulta.Fields[0].Value);
mtexto1 := Padr(mtexto1,Length(MenuItem.Caption));
Menuitem.Caption := MenuItem.Caption + ´ - ´;
MenuItem.Caption := MenuItem.Caption + FormatFloat(´000´ ,DataModule1.ADOQryConsulta.Fields[3].Value)+´ ´+
DataModule1.ADOQryConsulta.Fields[1].Text +´ ´+
FormatFloat(´0000000´ ,DataModule1.ADOQryConsulta.Fields[4].Value);
MenuItem.Tag := i;
MenuItem.OnClick := ClicaPreco;
PopupMenu1.Items.Add(MenuItem);
DataModule1.ADOQryConsulta.Next;
end;
MenuItem := TMenuItem.Create(nil);
MenuItem.Caption := FormatFloat(´000.00´,DataModule1.ADOQryProdutos.Fields[93].Value)+´ - ´+
FormatFloat(´000´ ,0 )+´ ´+
´ ´+
FormatFloat(´0000000´ ,0);
MenuItem.Tag := ++i;
MenuItem.OnClick := ClicaPreco;
PopupMenu1.Items.Add(MenuItem);
end
else
if DBGrid1.SelectedIndex = 5 then begin
if DataModule1.ADOQryPedidoItemQuantidade.Value = 0 then begin
messagedlg(´Voce precisa digitar o preço de venda!´,mterror,[mbOk],0);
DBGrid1.SelectedIndex := 5;
end
else begin
DataModule1.ADOQryPedidoItemTotal.Value := DataModule1.ADOQryPedidoItemQuantidade.Value * DataModule1.ADOQryPedidoItemPrecovenda.Value;
if messagedlg(´Confirma o Item para o Pedido ?´,mtconfirmation,[mbyes,mbno],0) = idyes then begin
BBtnGravarItemClick(Sender);
DBGrid1.SelectedIndex := 0;
end
else
DBGrid1.SelectedIndex := 5;
end
end
else
with TDBGrid(ActiveControl) do
if selectedindex < (fieldcount -1) then
selectedindex := selectedindex +1
else
selectedindex := 0;
end;
end;
DBGrid1.SetFocus;
DBGrid1.SelectedIndex := 0;
DBGrid1.SelectedField.Name :=´Produto´;
Atenciosamente,
Silvio Guedes.
silvioguedespb@hotmail.com
Consulte esta rotina abaixo para voce ter controle de dgitacao no DBGRID.
procedure TFmCadPedidos.DBGrid1KeyPress(Sender: TObject; var Key: Char);
var
mtexto : string;
i ,prazoped : integer;
mtexto1, mtexto2, mtexto3 : string;
begin
prazoped := 0 ;
if Key = #13 then begin
if not (ActiveControl is TDBGrid) then begin
Key := 0;
Perform(WM_NEXTDLGCTL, 0, 0);
end
else
if (DBGrid1.SelectedIndex = 0) then begin
if DbGrid1.SelectedField.AsString = ´´ then
PesqProduto(13,true)
else
PesqProduto(13,false)
end
else
if DBGrid1.SelectedIndex = 1 then begin
DataModule1.ADOQryPedidoItemDescProd.Value := DataModule1.ADOQryProdutosNome.Value;
DBGrid1.SelectedIndex := 4;
end
else
if DBGrid1.SelectedIndex = 4 then begin
if DataModule1.ADOQryPedidoItemQuantidade.Value = 0 then begin
messagedlg(´A quantidtidade digitada é zero, favo digite uma quantidade válida!´,mterror,[mbOk],0);
DBGrid1.SelectedIndex := 4;
end
else
if DataModule1.ADOQryPedidoItemPrecovenda.Value <> 0.00 then
DataModule1.ADOQryPedidoItemTotal.Value := DataModule1.ADOQryPedidoItemQuantidade.Value * DataModule1.ADOQryPedidoItemPrecovenda.Value;
DBGrid1.SelectedIndex := 5;
PopupMenu1.Items.Clear;
DataModule1.ADOQryConsulta.Close;
DataModule1.ADOQryConsulta.SQL.Clear;
DataModule1.ADOQryConsulta.SQL.Add(´select clientepreco.preco,formapag.descricao,formapag.prazomedio, ClientePreco.Quantidademinima,Clientepreco.prazo,Clientepreco.promocao, produtos.preço1 from clientepreco ´+
´inner join formapag on ´+
´formapag.codigo=clientepreco.prazo ´+
´inner join produtos on ´+
´produtos.código=´+DataModule1.ADOQryPedidoItemProduto.Text+
´ where cliente=´+QuotedStr(DataModule1.ADOQryPedidoCliente.Text)+
´ and produto=´+DataModule1.ADOQryPedidoItemProduto.Text+
´ and quantidademinima <= ´+QuotedStr(DataModule1.ADOQryPedidoItemQuantidade.Text)+
´ and formapag.prazomedio > 0 ´+
´order by preco´);
DataModule1.ADOQryConsulta.Open;
DataModule1.ADOQryConsulta.First;
for i := 1 to DataModule1.ADOQryConsulta.RecordCount do begin
MenuItem := TMenuItem.Create(nil);
mtexto1 := FormatFloat(´#,00.00´,DataModule1.ADOQryConsulta.Fields[0].Value);
mtexto1 := Padr(mtexto1,Length(MenuItem.Caption));
Menuitem.Caption := MenuItem.Caption + ´ - ´;
MenuItem.Caption := MenuItem.Caption + FormatFloat(´000´ ,DataModule1.ADOQryConsulta.Fields[3].Value)+´ ´+
DataModule1.ADOQryConsulta.Fields[1].Text +´ ´+
FormatFloat(´0000000´ ,DataModule1.ADOQryConsulta.Fields[4].Value);
MenuItem.Tag := i;
MenuItem.OnClick := ClicaPreco;
PopupMenu1.Items.Add(MenuItem);
DataModule1.ADOQryConsulta.Next;
end;
MenuItem := TMenuItem.Create(nil);
MenuItem.Caption := FormatFloat(´000.00´,DataModule1.ADOQryProdutos.Fields[93].Value)+´ - ´+
FormatFloat(´000´ ,0 )+´ ´+
´ ´+
FormatFloat(´0000000´ ,0);
MenuItem.Tag := ++i;
MenuItem.OnClick := ClicaPreco;
PopupMenu1.Items.Add(MenuItem);
end
else
if DBGrid1.SelectedIndex = 5 then begin
if DataModule1.ADOQryPedidoItemQuantidade.Value = 0 then begin
messagedlg(´Voce precisa digitar o preço de venda!´,mterror,[mbOk],0);
DBGrid1.SelectedIndex := 5;
end
else begin
DataModule1.ADOQryPedidoItemTotal.Value := DataModule1.ADOQryPedidoItemQuantidade.Value * DataModule1.ADOQryPedidoItemPrecovenda.Value;
if messagedlg(´Confirma o Item para o Pedido ?´,mtconfirmation,[mbyes,mbno],0) = idyes then begin
BBtnGravarItemClick(Sender);
DBGrid1.SelectedIndex := 0;
end
else
DBGrid1.SelectedIndex := 5;
end
end
else
with TDBGrid(ActiveControl) do
if selectedindex < (fieldcount -1) then
selectedindex := selectedindex +1
else
selectedindex := 0;
end;
end;
GOSTEI 0
Silviogs
05/04/2004
Lá vai.
DBGrid1.SetFocus;
DBGrid1.SelectedIndex := 0;
DBGrid1.SelectedField.Name :=´Produto´;
Atenciosamente,
Silvio Guedes.
silvioguedespb@hotmail.com
Consulte esta rotina abaixo para voce ter controle de dgitacao no DBGRID.
procedure TFmCadPedidos.DBGrid1KeyPress(Sender: TObject; var Key: Char);
var
mtexto : string;
i ,prazoped : integer;
mtexto1, mtexto2, mtexto3 : string;
begin
prazoped := 0 ;
if Key = #13 then begin
if not (ActiveControl is TDBGrid) then begin
Key := 0;
Perform(WM_NEXTDLGCTL, 0, 0);
end
else
if (DBGrid1.SelectedIndex = 0) then begin
if DbGrid1.SelectedField.AsString = ´´ then
PesqProduto(13,true)
else
PesqProduto(13,false)
end
else
if DBGrid1.SelectedIndex = 1 then begin
DataModule1.ADOQryPedidoItemDescProd.Value := DataModule1.ADOQryProdutosNome.Value;
DBGrid1.SelectedIndex := 4;
end
else
if DBGrid1.SelectedIndex = 4 then begin
if DataModule1.ADOQryPedidoItemQuantidade.Value = 0 then begin
messagedlg(´A quantidtidade digitada é zero, favo digite uma quantidade válida!´,mterror,[mbOk],0);
DBGrid1.SelectedIndex := 4;
end
else
if DataModule1.ADOQryPedidoItemPrecovenda.Value <> 0.00 then
DataModule1.ADOQryPedidoItemTotal.Value := DataModule1.ADOQryPedidoItemQuantidade.Value * DataModule1.ADOQryPedidoItemPrecovenda.Value;
DBGrid1.SelectedIndex := 5;
PopupMenu1.Items.Clear;
DataModule1.ADOQryConsulta.Close;
DataModule1.ADOQryConsulta.SQL.Clear;
DataModule1.ADOQryConsulta.SQL.Add(´select clientepreco.preco,formapag.descricao,formapag.prazomedio, ClientePreco.Quantidademinima,Clientepreco.prazo,Clientepreco.promocao, produtos.preço1 from clientepreco ´+
´inner join formapag on ´+
´formapag.codigo=clientepreco.prazo ´+
´inner join produtos on ´+
´produtos.código=´+DataModule1.ADOQryPedidoItemProduto.Text+
´ where cliente=´+QuotedStr(DataModule1.ADOQryPedidoCliente.Text)+
´ and produto=´+DataModule1.ADOQryPedidoItemProduto.Text+
´ and quantidademinima <= ´+QuotedStr(DataModule1.ADOQryPedidoItemQuantidade.Text)+
´ and formapag.prazomedio > 0 ´+
´order by preco´);
DataModule1.ADOQryConsulta.Open;
DataModule1.ADOQryConsulta.First;
for i := 1 to DataModule1.ADOQryConsulta.RecordCount do begin
MenuItem := TMenuItem.Create(nil);
mtexto1 := FormatFloat(´#,00.00´,DataModule1.ADOQryConsulta.Fields[0].Value);
mtexto1 := Padr(mtexto1,Length(MenuItem.Caption));
Menuitem.Caption := MenuItem.Caption + ´ - ´;
MenuItem.Caption := MenuItem.Caption + FormatFloat(´000´ ,DataModule1.ADOQryConsulta.Fields[3].Value)+´ ´+
DataModule1.ADOQryConsulta.Fields[1].Text +´ ´+
FormatFloat(´0000000´ ,DataModule1.ADOQryConsulta.Fields[4].Value);
MenuItem.Tag := i;
MenuItem.OnClick := ClicaPreco;
PopupMenu1.Items.Add(MenuItem);
DataModule1.ADOQryConsulta.Next;
end;
MenuItem := TMenuItem.Create(nil);
MenuItem.Caption := FormatFloat(´000.00´,DataModule1.ADOQryProdutos.Fields[93].Value)+´ - ´+
FormatFloat(´000´ ,0 )+´ ´+
´ ´+
FormatFloat(´0000000´ ,0);
MenuItem.Tag := ++i;
MenuItem.OnClick := ClicaPreco;
PopupMenu1.Items.Add(MenuItem);
end
else
if DBGrid1.SelectedIndex = 5 then begin
if DataModule1.ADOQryPedidoItemQuantidade.Value = 0 then begin
messagedlg(´Voce precisa digitar o preço de venda!´,mterror,[mbOk],0);
DBGrid1.SelectedIndex := 5;
end
else begin
DataModule1.ADOQryPedidoItemTotal.Value := DataModule1.ADOQryPedidoItemQuantidade.Value * DataModule1.ADOQryPedidoItemPrecovenda.Value;
if messagedlg(´Confirma o Item para o Pedido ?´,mtconfirmation,[mbyes,mbno],0) = idyes then begin
BBtnGravarItemClick(Sender);
DBGrid1.SelectedIndex := 0;
end
else
DBGrid1.SelectedIndex := 5;
end
end
else
with TDBGrid(ActiveControl) do
if selectedindex < (fieldcount -1) then
selectedindex := selectedindex +1
else
selectedindex := 0;
end;
end;
DBGrid1.SetFocus;
DBGrid1.SelectedIndex := 0;
DBGrid1.SelectedField.Name :=´Produto´;
Atenciosamente,
Silvio Guedes.
silvioguedespb@hotmail.com
Consulte esta rotina abaixo para voce ter controle de dgitacao no DBGRID.
procedure TFmCadPedidos.DBGrid1KeyPress(Sender: TObject; var Key: Char);
var
mtexto : string;
i ,prazoped : integer;
mtexto1, mtexto2, mtexto3 : string;
begin
prazoped := 0 ;
if Key = #13 then begin
if not (ActiveControl is TDBGrid) then begin
Key := 0;
Perform(WM_NEXTDLGCTL, 0, 0);
end
else
if (DBGrid1.SelectedIndex = 0) then begin
if DbGrid1.SelectedField.AsString = ´´ then
PesqProduto(13,true)
else
PesqProduto(13,false)
end
else
if DBGrid1.SelectedIndex = 1 then begin
DataModule1.ADOQryPedidoItemDescProd.Value := DataModule1.ADOQryProdutosNome.Value;
DBGrid1.SelectedIndex := 4;
end
else
if DBGrid1.SelectedIndex = 4 then begin
if DataModule1.ADOQryPedidoItemQuantidade.Value = 0 then begin
messagedlg(´A quantidtidade digitada é zero, favo digite uma quantidade válida!´,mterror,[mbOk],0);
DBGrid1.SelectedIndex := 4;
end
else
if DataModule1.ADOQryPedidoItemPrecovenda.Value <> 0.00 then
DataModule1.ADOQryPedidoItemTotal.Value := DataModule1.ADOQryPedidoItemQuantidade.Value * DataModule1.ADOQryPedidoItemPrecovenda.Value;
DBGrid1.SelectedIndex := 5;
PopupMenu1.Items.Clear;
DataModule1.ADOQryConsulta.Close;
DataModule1.ADOQryConsulta.SQL.Clear;
DataModule1.ADOQryConsulta.SQL.Add(´select clientepreco.preco,formapag.descricao,formapag.prazomedio, ClientePreco.Quantidademinima,Clientepreco.prazo,Clientepreco.promocao, produtos.preço1 from clientepreco ´+
´inner join formapag on ´+
´formapag.codigo=clientepreco.prazo ´+
´inner join produtos on ´+
´produtos.código=´+DataModule1.ADOQryPedidoItemProduto.Text+
´ where cliente=´+QuotedStr(DataModule1.ADOQryPedidoCliente.Text)+
´ and produto=´+DataModule1.ADOQryPedidoItemProduto.Text+
´ and quantidademinima <= ´+QuotedStr(DataModule1.ADOQryPedidoItemQuantidade.Text)+
´ and formapag.prazomedio > 0 ´+
´order by preco´);
DataModule1.ADOQryConsulta.Open;
DataModule1.ADOQryConsulta.First;
for i := 1 to DataModule1.ADOQryConsulta.RecordCount do begin
MenuItem := TMenuItem.Create(nil);
mtexto1 := FormatFloat(´#,00.00´,DataModule1.ADOQryConsulta.Fields[0].Value);
mtexto1 := Padr(mtexto1,Length(MenuItem.Caption));
Menuitem.Caption := MenuItem.Caption + ´ - ´;
MenuItem.Caption := MenuItem.Caption + FormatFloat(´000´ ,DataModule1.ADOQryConsulta.Fields[3].Value)+´ ´+
DataModule1.ADOQryConsulta.Fields[1].Text +´ ´+
FormatFloat(´0000000´ ,DataModule1.ADOQryConsulta.Fields[4].Value);
MenuItem.Tag := i;
MenuItem.OnClick := ClicaPreco;
PopupMenu1.Items.Add(MenuItem);
DataModule1.ADOQryConsulta.Next;
end;
MenuItem := TMenuItem.Create(nil);
MenuItem.Caption := FormatFloat(´000.00´,DataModule1.ADOQryProdutos.Fields[93].Value)+´ - ´+
FormatFloat(´000´ ,0 )+´ ´+
´ ´+
FormatFloat(´0000000´ ,0);
MenuItem.Tag := ++i;
MenuItem.OnClick := ClicaPreco;
PopupMenu1.Items.Add(MenuItem);
end
else
if DBGrid1.SelectedIndex = 5 then begin
if DataModule1.ADOQryPedidoItemQuantidade.Value = 0 then begin
messagedlg(´Voce precisa digitar o preço de venda!´,mterror,[mbOk],0);
DBGrid1.SelectedIndex := 5;
end
else begin
DataModule1.ADOQryPedidoItemTotal.Value := DataModule1.ADOQryPedidoItemQuantidade.Value * DataModule1.ADOQryPedidoItemPrecovenda.Value;
if messagedlg(´Confirma o Item para o Pedido ?´,mtconfirmation,[mbyes,mbno],0) = idyes then begin
BBtnGravarItemClick(Sender);
DBGrid1.SelectedIndex := 0;
end
else
DBGrid1.SelectedIndex := 5;
end
end
else
with TDBGrid(ActiveControl) do
if selectedindex < (fieldcount -1) then
selectedindex := selectedindex +1
else
selectedindex := 0;
end;
end;
GOSTEI 0