10

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

colin
  • 2,983
  • 6
  • 41
  • 49

4 Answers4

19

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;
...
saastn
  • 5,717
  • 8
  • 47
  • 78
roumen
  • 563
  • 6
  • 15
2

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

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

André
  • 8,920
  • 1
  • 24
  • 24
1
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?

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • Thats what I thought, however I am using Delphi 7 and this does not seem to be supported. – colin Sep 14 '10 at 19:40
  • That helps however the scroll bars still flicker – colin Sep 14 '10 at 20:11
  • 2
    Now that I look through the code, it is evident to me that the `TStringGrid` is not the best control on the planet. One thing I really do not like with this control, is that it is not themed -- it looks odd in a themed application. Are you sure that you cannot do with a `TListView`? – Andreas Rejbrand Sep 14 '10 at 20:17
  • What about using DoubleBuffered for the panel which contains the scrollbars? – Name Sep 21 '10 at 12:10
-2

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.

Daniel Luyo
  • 1,326
  • 13
  • 19
  • 5
    [With what operations is LockWindowUpdate meant to be used?](http://blogs.msdn.com/b/oldnewthing/archive/2007/02/21/1735472.aspx) [With what operations is LockWindowUpdate not meant to be used?](http://blogs.msdn.com/b/oldnewthing/archive/2007/02/22/1742084.aspx) Use [`wm_SetRedraw`](http://msdn.microsoft.com/en-us/library/dd145219.aspx) instead. – Rob Kennedy Sep 14 '10 at 22:00
  • OK, then you should put it as an Answer not a comment – Daniel Luyo Sep 14 '10 at 23:21
  • 1
    I think Rob was explaining to you why your answer was wrong and being downvoted, and thus his comment was correctly a comment (to you). – Ken White Sep 15 '10 at 12:46
  • I'm an eternal novice, and I'm happy to learn new things every day. I fully read the link posted by Rob, and also the MSDN documentation to clear my doubts. Despite the fact that the function LockWindowUpdate will do the job event it's not intendend for. I'm suggesting Rob to post an answer so the question does not appear as unanswered that's all – Daniel Luyo Sep 15 '10 at 15:28
  • The valuable links @Rob gave us have changed. Here are new ones: [With what operations is LockWindowUpdate meant to be used?](https://blogs.msdn.microsoft.com/oldnewthing/20070221-11/?p=27933/) and [With what operations is LockWindowUpdate not meant to be used?](https://blogs.msdn.microsoft.com/oldnewthing/20070222-01/?p=27913/) – Tom Brunberg Jan 15 '16 at 16:37