虽然dbgrideh里有设置,但是如果设置了,在keypress里就收不到回车消息了。 因为想在按下回车后做一些事再跳到下一格,但是下面代码却没办法实现。 if Key = #13 then begin SendMessage(StockPlanList.Handle,WM_NEXTDLGCTL,0,0); end;
KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = 13) or (Key = 9) then
PostMessage(Self.Handle, WM_KEYDOWN, VK_TAB, 0);
end
procedure TFrmDepotTOutGl.FormKeyPress(Sender: TObject; var Key: Char);
begin
if (key = #13)And(not (ActiveControl is TMemo)) then
if not (ActiveControl is TDbGrid) then
begin
Key := #0;
Perform(Wm_NextDlgCtl,0,0);
end else
if (ActiveControl is TDbGrid) then
begin
With TDbGrid(ActiveControl) do
if SelectedIndex < (FieldCount - 1) then
SelectedIndex := SelectedIndex + 1
else
SelectedIndex := 0;
end;
end;
没用过这个,但是应该是在
procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);中
写代码,
if DBGrid1.DataSource1.DataSet1.acive then
begin
if Key = #13 then
DBGrid1.DataSource1.DataSet1.next;
判断当到了最后条时,跳到第一条,或者你做其他处理;
end;
这样就行:
procedure TForm1.dbgPrintListKeyPress(Sender: TObject; var Key: Char);
begin
if Ord(Key) = VK_RETURN then
if ActiveControl = dbgPrintList then
begin
TDBGrid(ActiveControl).SelectedIndex := TDBGrid(ActiveControl).SelectedIndex + 1;
Key := #0;
end;
end;