procedure TForm1.Edit1KeyPress (Sender: TObject; var Key: Char) ;
begin
   If Key = #13 Then Begin
    If HiWord(GetKeyState(VK_SHIFT)) <> 0 then
     SelectNext(Sender as TWinControl,False,True)
    else
     SelectNext(Sender as TWinControl,True,True) ;
     Key := #0
   end;
end;

~~~~~~~~~~~~~~~~~~~~~~~~~
in DBGrid

If you want to have similar Enter (Shift+Enter) processing in DBGrid:
~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.DBGrid1KeyPress (Sender: TObject; var Key: Char) ;
begin
   If Key = #13 Then Begin
    If HiWord(GetKeyState(VK_SHIFT)) <> 0 then begin
     with (Sender as TDBGrid) do
     if selectedindex > 0 then
      selectedindex := selectedindex - 1
     else begin
      DataSource.DataSet.Prior;
      selectedindex := fieldcount - 1;
     end;
    end else begin
     with (Sender as TDBGrid) do
     if selectedindex < (fieldcount - 1) then
      selectedindex := selectedindex + 1
     else begin
      DataSource.DataSet.Next;
      selectedindex := 0;
     end;
   end;
   Key := #0
   end;
end;

~~~~~~~~~~~~~~~~~~~~~~~~~

posted on 2012-12-05 11:55  许小东  阅读(181)  评论(0编辑  收藏  举报