Link to home
Start Free TrialLog in
Avatar of chrisbray
chrisbrayFlag for United Kingdom of Great Britain and Northern Ireland

asked on

BeginUpdate for TStringGrid

I have a string grid and it flashes whilst data being written to the cells.  I would like to implement something like BeginUpdate and EndUpdate but these do not seem to be implemented in the TStringGrid - anybody suggest how this could be done?

Chris Bray.
Avatar of Russell Libby
Russell Libby
Flag of United States of America image

You could try locking the stringlists that make up the columns, eg:

procedure LockGrid(Grid: TStringGrid);
var  dwIndex:       Integer;
begin

  // Walk the columns and lock the string list for each
  for dwIndex:=0 to Pred(Grid.ColCount) do
  begin
     Grid.Cols[dwIndex].BeginUpdate;
  end;

end;

procedure UnLockGrid(Grid: TStringGrid);
var  dwIndex:       Integer;
begin

  // Walk the columns and unlock the string list for each
  for dwIndex:=0 to Pred(Grid.ColCount) do
  begin
     Grid.Cols[dwIndex].EndUpdate;
  end;

end;

// Example usage
procedure TForm1.Button1Click(Sender: TObject);
var  dwIndex:       Integer;
     dwCols:        Integer;

begin

  LockGrid(StringGrid1);
  try
     for dwIndex:=0 to Pred(StringGrid1.RowCount) do
     begin
        for dwCols:=0 to Pred(StringGrid1.ColCount) do
        begin
           StringGrid1.Cells[dwCols, dwIndex]:=Format('%d, %d', [dwCols, dwIndex]);
        end;
     end;
  finally
     UnLockGrid(StringGrid1);
  end;

end;


Regards,
Russell
ASKER CERTIFIED SOLUTION
Avatar of ZhaawZ
ZhaawZ
Flag of Latvia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chrisbray

ASKER

Hi Guys,

Thanks for your answers.  ZhaawZ gave the quickest and most effective answer, so I have given him the points.  Excellent stuff!

Chris Bray.
glad to help