2011-10-19 54 views
7

我有一個TGrid與混合列(ImageColumn和StringColumn)。我可以使用onGetValue事件填充它,它可以正常工作。我的問題是:德爾福Firemonkey TGrid如何更新

  1. 如何強制整個網格重建並導致onGetValue事件? 我正在使用UpdateStyle。

  2. 如何更新網格中的單個單元格?

回答

5

該網格只更新可見的單元格! 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; 

細胞不分配。

+0

感謝您的回覆,完美的回答。 –

2

另一種選擇是致電Grid1.beginUpdate;進行更改,然後致電Grid1.endupdate;這將導致可見網格重新計算和重繪。