Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi Firemonkey TGrid how to update

I have a TGrid with a mixture of columns (ImageColumn and StringColumn). I can populate it using onGetValue event which works fine. My questions are:

  1. How to force the entire grid to rebuild and cause onGetValue event? I'm using UpdateStyle at the monent.

  2. How can I update a single cell in the grid?

like image 791
Alan Grace Avatar asked Oct 19 '11 13:10

Alan Grace


2 Answers

The grid updates only visible cells! Grid1.UpdateStyle force the grid to rebuild and is causing onGetValue events but its slow. Grid1.ReAlign is much faster.

As soon as cells become visible, they will be updated.

Updating 1 cell:

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;

cell is not assigned when row never become visible.

like image 99
Arjen van der Spek Avatar answered Oct 10 '22 16:10

Arjen van der Spek


The other option is to call Grid1.beginUpdate; make your changes and then call Grid1.endupdate; which will cause the visible grid to recalculate and redraw.

like image 22
skamradt Avatar answered Oct 10 '22 17:10

skamradt