我在XP SP3机器上运行Delphi7Enterprise。
我可以使用:TEdit.SetFocus;在TEdit上设置焦点
我可以使用TStringGrid.SetFocus;在TStringGrid上设置焦点
但是,这只是我想要的一部分。
如何在TStringGrid中的某个单元格(列/行)上设置焦点
TStringGrid.SetFocus(Col,Row)
发布于 2021-02-22 23:17:27
您可以为要关注的单元格定义一个TGridRect (选择),或者定义要关注的单元格范围(如果在Options中有goRangeSelect = True。
然后选择该TGridRect。
示例:
procedure TForm30.Button1Click(Sender: TObject);
var
AGridRect: TGridRect;
begin
AGridRect.Left := 2;
AGridRect.Top := 2;
AGridRect.Right := 2;
AGridRect.Bottom := 2;
StringGrid1.Selection := AGridRect;
end;发布于 2021-02-23 01:09:02
您可以使用网格的Col和Row属性:
指定包含选定单元格的列的索引。指定包含选定单元格的行的索引。
StringGrid1.SetFocus;
StringGrid1.Col := Col;
StringGrid1.Row := Row;它只在内部调用网格的受保护的FocusCell()方法,您可以使用访问器类直接调用该方法:
type
TStringGridAccess = class(TStringGrid)
end;
StringGrid1.SetFocus;
TStringGridAccess(StringGrid1).FocusCell(Col, Row, True);https://stackoverflow.com/questions/66318151
复制相似问题