views:

175

answers:

3

Hi 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

A: 
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
Thats what I thought, however I am using Delphi 7 and this does not seem to be supported.
That helps however the scroll bars still flicker
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
What about using DoubleBuffered for the panel which contains the scrollbars?
Name
A: 

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
[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
OK, then you should put it as an Answer not a comment
Daniel Luyo
@Daniel: 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
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
Daniel - If you want @Rob to be notified of your comment include an `@` before his name. See: http://meta.stackoverflow.com/questions/43019/how-do-comment-replies-work
Sertac Akyuz
A: 

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é