Delphi TStringGrid Flicker
Asked Answered
L

4

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

Lore answered 14/9, 2010 at 19:30 Comment(0)
P
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;
...
Propitiate answered 17/8, 2011 at 21:50 Comment(0)
S
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;

Senate answered 15/9, 2010 at 5:54 Comment(1)
does it work ? especially if the gird is re-filled using .Cells ?Lazaro
S
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?

Stivers answered 14/9, 2010 at 19:36 Comment(4)
Thats what I thought, however I am using Delphi 7 and this does not seem to be supported.Lore
That helps however the scroll bars still flickerLore
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?Stivers
What about using DoubleBuffered for the panel which contains the scrollbars?Kowal
P
-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.

Perfect answered 14/9, 2010 at 21:28 Comment(5)
With what operations is LockWindowUpdate meant to be used? With what operations is LockWindowUpdate not meant to be used? Use wm_SetRedraw instead.Mountainous
OK, then you should put it as an Answer not a commentPerfect
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).Bodoni
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 allPerfect
The valuable links @Rob gave us have changed. Here are new ones: With what operations is LockWindowUpdate meant to be used? and With what operations is LockWindowUpdate not meant to be used?Gabbie

© 2022 - 2024 — McMap. All rights reserved.