就是我用DBGRID显示一个表, 假设表依次有三个字段 A B C 我要实现的按键效果是 输入记录时 我先在A中输了一个内容,回车后光标自动跳到B字段,再输入B的内容,回车后,光标自动又跳到C, 输入C的内容后, 回车,此时出现一行新的空白记录用于输入,并且光标跳回A字段,准备进行新的输入,如何实现??
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if (Key = #13) and (Screen.ActiveForm.ActiveControl is TDbGridEh) then
with TDbGridEh(Screen.ActiveForm.ActiveControl) do
begin
if (ADOQuery1.State = dsEdit) then ADOQuery1.Post ;
if SelectedIndex < FieldCount -1 then
SelectedIndex := SelectedIndex + 1
else
begin
with ADOQuery1 do
begin
if (ADOQuery1.State = dsEdit) or (ADOQuery1.State = dsInsert) then ADOQuery1.Post ;
Close ;
Open ;
Append ;
end ;
SelectedIndex := 0 ;
end ;
end ;
我用的是DBGRIDEH示例如下:
procedure TJSCLForm.DBGridEh1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key = VK_DOWN) and (dbgrideh1.row = 4) then
//自动向后移动光标,并防止新增记录。4为最末记录号,可以修改为DATASET.RECORDCOUNT
begin
key := 13;
end;
end;