Delphi TStringGrid Flicker

2019-01-18 06:00发布

I am adding multiple rows to a string grid from a CSV file @ runtime, However the StringGrid seems to flicker lots when it is being upadated, I presumed there would be a beginupadate / Endupdate command to stop this. However I cannot find it. Is there another way to stop the flicker when the grid id being updated.

Colin

4条回答
该账号已被封号
2楼-- · 2019-01-18 06:17
These are methods of the `TStrings` object. Use StringGrid1.Rows[i]/Cols[i].BeginUpdate; ... StringGrid1.Rows[i]/Cols[i].EndUpdate;

Update

Have you tried to set DoubleBuffered := true?

查看更多
该账号已被封号
3楼-- · 2019-01-18 06:24

Better late than never... I use WM_SETREDRAW. For example:

...
StringGrid1.Perform(WM_SETREDRAW, 0, 0);
try
  // StringGrid1 is populated with the data here 
finally
  StringGrid1.Perform(WM_SETREDRAW, 1, 0);
  StringGrid1.Invalidate; // important! to force repaint after all
end;
...
查看更多
成全新的幸福
4楼-- · 2019-01-18 06:28

You can use the Windows function LockWindowUpdate(AHandle) to prevent the refresh of the control and then LockWindowUpdate(0) to repaint it.

As the handle pass the Grid.Handle.

查看更多
Juvenile、少年°
5楼-- · 2019-01-18 06:29

Yes, there is no BeginUpdate/EndUpdate in TStringgrid, but there is per row or per col:

StringGrid1.Rows[0].BeginUpdate;
StringGrid1.Cols[0].BeginUpdate;

查看更多
登录 后发表回答