如何屏閉DBGRID內的TAB鍵,讓TAB在跳到該行最后時跳到上面的DBEDIT1上﹐不讓它增加
下一筆記錄

解决方案 »

  1.   

    if key=char(vk_return) and (edit_last.setfocus()) then
     beginedit1.setfocus()
     end;
      

  2.   

    //dgeStore为DBGridEh,也适用于DBGrid
    procedure TfrmEhlib.dgeStoreKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if (Key = VK_TAB) and (dgeStore.Row = dgeStore.RowCount - 1) and
         (dgeStore.SelectedIndex = dgeStore.FieldCount - 1) then
      begin
        Edit1.SetFocus;
        Key := 0;
      end;
    end;
      

  3.   

    也可写在其OnKeyUp事件中,和OnKeyDown中代码一下,下面是写在OnKeyPress中:
    procedure TfrmEhlib.dgeStoreKeyPress(Sender: TObject; var Key: Char);
    begin
      if (Key = #9) and (dgeStore.Row = dgeStore.RowCount - 1) and
         (dgeStore.SelectedIndex = dgeStore.FieldCount - 1) then
      begin
        Edit1.SetFocus;
        Key := #0;
      end;
    end;