11

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?

Michael Küller
  • 3,982
  • 4
  • 22
  • 42
Alan Grace
  • 171
  • 1
  • 6

2 Answers2

6

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.

skamradt
  • 15,366
  • 2
  • 36
  • 53
6

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.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Arjen van der Spek
  • 2,630
  • 16
  • 20