11

我有一个混合列(ImageColumn 和 StringColumn)的 TGrid。我可以使用工作正常的 onGetValue 事件填充它。我的问题是:

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

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

4

2 回答 2

6

网格只更新可见单元格!Grid1.UpdateStyle强制网格重建并导致onGetValue事件,但速度很慢。Grid1.ReAlign快得多。

一旦单元格变得可见,它们就会被更新。

更新 1 个单元格:

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;

当行永远不可见时,不分配单元格。

于 2011-10-19T17:30:33.307 回答
6

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

于 2016-11-17T09:06:02.027 回答