StringGrid通过回车键切换单元格。
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if Key=#13 then
begin
With StringGrid1 do
begin
if Col<ColCount-1 then
begin
Col:=Col+1;
end
else//换行
if Row<RowCount-1 then
begin
Row:=Row+1;
Col:=0;
end
else //回到第一个单元格
if (Row=RowCount-1) and (Col=ColCount-1) then
begin
Row:=0;
Col:=0;
end;
end;
end;
end;
本文介绍了一个使用Delphi编写的程序片段,该程序能够实现在StringGrid中通过按下回车键来切换到下一个单元格的功能。具体实现包括在同一行内向右移动光标直至到达最后一列,然后换行并跳转到下一行的第一列,如果已到达表格的最后一行一列,则返回到表格的起始位置。
305

被折叠的 条评论
为什么被折叠?



