Delphi 中禁止 FMX 框架的 TStringGrid 单元格被选中

cnblogs 2024-10-16 17:39:00 阅读 71

Delphi 中禁止 FMX 框架的 TStringGrid 单元格被选中

Delphi 中禁止 FMX 框架的 TStringGrid 单元格被选中

环境

    <li>Windows 11 23H2
  1. Delphi 12 Update 1
  2. Multi-Device Application

使用 Delphi 中 FMX 框架的 TStringGrid 展示数据而不愿意某个单元格被选中时,曾经的 VCL 手段是把选中位置调整到无效位置从而实际上使得单元格无法被选中。阅读文档偶然发现 OnSelectCell 事件提供了很简单也更规范的方法实现了这一目的。

<code>procedure TFrom.StrGrdSelectCell(Sender: TObject; const ACol, ARow: Integer; var CanSelect: Boolean);

begin

CanSelect := False;

end;

在 FMX 框架中测试此方法有效。在 VCL 代码中观察到使用此方法的效果不理想。设置CanSelect := False后在程序启动时依然有某个单元格处于被选中的渲染状态。

文档地址: Vcl.Grids.TCustomDrawGrid.OnSelectCell

Occurs before a cell in the grid is selected.

Write an OnSelectCell event handler to specify whether any particular cell in the grid can be selected. The Col and Row parameters indicate the column and row indexes of the cell that is about to be selected. Set the CanSelect parameter to False to prevent the cell being selected.


上一篇: 【QT】常用控件(一)

下一篇: Python入门:A+B问题

本文标签

delphi    OnSelectCell    TStringGrid   


声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。