Delphi Firemonkey TGrid 如何更新数据?

11

我有一个包含图像列和字符串列的TGrid。我可以使用onGetValue事件填充它,运行良好。我的问题是:

  1. 如何强制整个网格重建并引发onGetValue事件?我目前正在使用UpdateStyle。

  2. 如何更新网格中的单个单元格?


Note: "TGrid"可能是应用程序或库中自定义的组件名称,未翻译。
2个回答

6
网格只更新可见单元格! Grid1.UpdateStyle 强制网格进行重建并触发 onGetValue 事件,但速度较慢。使用 Grid1.ReAlign 则快得多。
一旦单元格变为可见状态,它们将会被更新。
更新一个单元格:
procedure TForm1.UpdateCell(col, row: integer);
var
  cell: TStyledControl;
begin
  cell := Grid1.Columns[col].CellControlByRow(row);
  if Assigned(cell) then
    cell.Data := 'Note: use the same datasource as OnGetValue';
end;

当行从未变为可见状态时,单元格未被分配。


6
另一种选择是调用Grid1.beginUpdate;进行更改,然后调用Grid1.endupdate;使可见网格重新计算和重绘。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接