1,2 procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key = VK_RETURN) then if (StringGrid1.Row < StringGrid1.RowCount -1) then begin if (StringGrid1.Col = 0) then StringGrid1.Row := StringGrid1.Row + 1 else begin StringGrid1.Row := StringGrid1.Row + 1; StringGrid1.Col := 0; end; end; end;3 procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char); begin if (StringGrid1.Col = 1) and not(Key in['0'..'9', '.', #8]) then Key := #0; end;
1. procedure TForm1.FormActivate(Sender: TObject); begin StringGrid1.Col := 0; StringGrid1.Row := 1; end; 2. procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key = VK_RETURN) then if (StringGrid1.Row < StringGrid1.RowCount -1) then begin if (StringGrid1.Col = 0) then StringGrid1.Col := StringGrid1.Col + 1 else begin StringGrid1.Row := StringGrid1.Row + 1; StringGrid1.Col := 0; end; end; end;
设置 StringGrid.Row 行数 StringGrid.Col 列数 即可
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin {2.~~} if key=13 then if (StringGrid1.Col=1) and(StringGrid1.Row<StringGrid1.RowCount) then begin StringGrid1.Row:=StringGrid1.Row+1; StringGrid1.Col:=0; end else if (StringGrid1.Col=0) then StringGrid1.Col:=1; end;procedure TForm1.FormCreate(Sender: TObject); begin {1.~~} StringGrid1.Row:=0; StringGrid1.Col:=0; end;procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char); begin {3.~~} if StringGrid1.Col=1 then if not (key in ['0'..'9']) and (key<>'.') and (key<>#13) then key:=#0; end;
StringGrid1.Options->goAlwaysShowEditor设置为True
StringGrid1.SetFocus; StringGrid1.Options->goAlwaysShowEditor设置为True procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=13 then if (StringGrid1.Col=1) and(StringGrid1.Row<StringGrid1.RowCount) then begin StringGrid1.Row:=StringGrid1.Row+1; StringGrid1.Col:=0; end else if (StringGrid1.Col=0) then StringGrid1.Col:=1; end;procedure TForm1.FormCreate(Sender: TObject); begin StringGrid1.Row:=0; StringGrid1.Col:=0; end;procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char); begin if StringGrid1.Col=1 then if not (key in ['0'..'9']) and (key<>'.') and (key<>#13) then key:=#0; end;
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_RETURN) then
if (StringGrid1.Row < StringGrid1.RowCount -1) then
begin
if (StringGrid1.Col = 0) then
StringGrid1.Row := StringGrid1.Row + 1
else
begin
StringGrid1.Row := StringGrid1.Row + 1;
StringGrid1.Col := 0;
end;
end;
end;3
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if (StringGrid1.Col = 1) and not(Key in['0'..'9', '.', #8]) then
Key := #0;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
StringGrid1.Col := 0;
StringGrid1.Row := 1;
end;
2.
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_RETURN) then
if (StringGrid1.Row < StringGrid1.RowCount -1) then
begin
if (StringGrid1.Col = 0) then
StringGrid1.Col := StringGrid1.Col + 1
else
begin
StringGrid1.Row := StringGrid1.Row + 1;
StringGrid1.Col := 0;
end;
end;
end;
StringGrid.Row 行数
StringGrid.Col 列数
即可
Shift: TShiftState);
begin
{2.~~}
if key=13 then
if (StringGrid1.Col=1) and(StringGrid1.Row<StringGrid1.RowCount) then
begin
StringGrid1.Row:=StringGrid1.Row+1;
StringGrid1.Col:=0;
end else
if (StringGrid1.Col=0) then
StringGrid1.Col:=1;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
{1.~~}
StringGrid1.Row:=0;
StringGrid1.Col:=0;
end;procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
{3.~~}
if StringGrid1.Col=1 then
if not (key in ['0'..'9']) and (key<>'.') and (key<>#13) then
key:=#0;
end;
StringGrid1.Options->goAlwaysShowEditor设置为True
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=13 then
if (StringGrid1.Col=1) and(StringGrid1.Row<StringGrid1.RowCount) then
begin
StringGrid1.Row:=StringGrid1.Row+1;
StringGrid1.Col:=0;
end else
if (StringGrid1.Col=0) then
StringGrid1.Col:=1;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Row:=0;
StringGrid1.Col:=0;
end;procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if StringGrid1.Col=1 then
if not (key in ['0'..'9']) and (key<>'.') and (key<>#13) then
key:=#0;
end;