简体   繁体   中英

Delphi: dbgrid cell press enter to go next cell

I am working with ADO components to connect Access database on Delphi 2010. I wish , as MS Excel, when pressing ENTER adotable.post and next below cell be will selected.

 procedure TForm4.DBGrid1Enter(Sender: TObject);
 begin
 adotable1.Edit;
 adotable1.Post;
 ....{below cell will be selected}
 end;

The code below, which is about as simple as it gets, should do what you want.

procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_Return then 
    Key := VK_Down;
end;

Btw, this code is to be used instead of, not as well as, the code in your q.

(This answer replaces one I posted earlier that involved manipulating the dataset feeding the grid, and did not work in all cases, like when dgMultiSelect is set true).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM