//在按键事件里切换焦点 with StringGrid do begin Row := XX; Col := XX; SetFocus; end;
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_RETURN then begin if bReturnKey then begin bReturnKey := False; with StringGrid1 do if Col < ColCount - 1 then Col := Col + 1 else if Row < RowCount - 1 then begin Row := Row + 1; Col := 0; end; end else bReturnKey := True; end; end;
会车时 i:=1;再按i:=2;
flag:=0;
回车后
flag:=flag+1;
with StringGrid do
begin
Row := XX;
Col := XX;
SetFocus;
end;
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then
begin
if bReturnKey then
begin
bReturnKey := False;
with StringGrid1 do
if Col < ColCount - 1 then
Col := Col + 1
else
if Row < RowCount - 1 then
begin
Row := Row + 1;
Col := 0;
end;
end
else
bReturnKey := True;
end;
end;