hello, I am using TdbGrid and I want to show some values from it in another fields, when user clicks on it.
The solution is simple
I used a Query named Query1 and a Datasource and a DBGrid1CellClick event like this:
procedure TFormWallet.DBGrid1CellClick(Column: TColumn);
begin
if query1.FieldByName('col_2').Value <> null then
edtCol_2.Text:=Query1.FieldByName('col_2').Value else edtCol_2.Text:='' ;
if query1.FieldByName('col_10').Value <> null then
edtCol_10.Text:=Query1.FieldByName('col_10').Value else edtCol_10.Text:='';
if query1.FieldByName('col_14').Value <> null then
edtCol_14.Text:=Query1.FieldByName('col_14').Value else edtCol_14.Text:='';
end;
It works fine, but the problem is, when I want to do the same when user uses keyboard, when I use KeyDownEvent simillar DBGridClick event like this
procedure TFormWallet.DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
// query1.RecNo:=query1.RecNo+1 ;
if query1.FieldByName('col_2').Value <> null then
edtCol_2.Text:=Query1.FieldByName('col_2').Value else edtCol_2.Text:='' ;
if query1.FieldByName('col_10').Value <> null then
edtCol_10.Text:=Query1.FieldByName('col_10').Value else edtCol_10.Text:='';
if query1.FieldByName('col_14').Value <> null then
edtCol_14.Text:=Query1.FieldByName('col_14').Value else edtCol_14.Text:='';
// query1.RecNo:=query1.RecNo-1;
end;
record is the previous, and that is the problem, I tried the solution with RecNo modification (commented here, but it is very stupid), even if I want to write KeyUpEvent too
PLease do you know better solution?
Thank you very much for help.