我有一个包含图像列和字符串列的TGrid。我可以使用onGetValue事件填充它,运行良好。我的问题是:
如何强制整个网格重建并引发onGetValue事件?我目前正在使用UpdateStyle。
如何更新网格中的单个单元格?
Note: "TGrid"可能是应用程序或库中自定义的组件名称,未翻译。
我有一个包含图像列和字符串列的TGrid。我可以使用onGetValue事件填充它,运行良好。我的问题是:
如何强制整个网格重建并引发onGetValue事件?我目前正在使用UpdateStyle。
如何更新网格中的单个单元格?
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;
当行从未变为可见状态时,单元格未被分配。
Grid1.beginUpdate;
进行更改,然后调用Grid1.endupdate;
使可见网格重新计算和重绘。