I googled and found a lot of advice, but it all seemed several years old and none of it helped.
I have a string grid with 8 columns and once I get more than a few hundred rows it is taking over 2 seconds to populate (I compared using GetTickCount).
I tried StringGrid.Perform(WM_SETREDRAW, 0, 0)
(and 0, 1
at the end). I tried setting
Visible := False
while updating. Both to no use.
There is no BeginUpdate()
method.
Any advice? Delphi XE2 starter. I would be willing to use a FOSS 3rd party VCL string grid if it is tried & tested.
[Update] using TDrawGrid ... "A TDrawGrid doesn't have a property "Cells", like its brother TStringGrid. Your code has to calculate where to display the data and next it must draw a representation of the data on the "Canvas" of the grid."
That sounds like a lot of work to me :-(
Using VirtualTreeView - sounds ok if it is fast enough. I just won't have any child nodes. (update++ I just read this on the homepage "Virtual Treeview is extremely fast. Adding one million nodes takes only 700 milliseconds"). No problems on speed, then. But it woudl nice to just use a string grid. Escpecially one where the user can click & sort.
Alternatively, the stringgrid is only 20 rows high. Maybe I could just handle scrolbar clicks and clear & repopulate those 20 rows when the user scrols?
[Furtehr update] I changed from TStringGrid to TListView which codes have Beginupdate())
, but that made a negligible difference. Ops, I forgot "viortual mode" - brb.
Btw, the data are read-only, just for disply.
Surely this is a very common probem?
TStringGrid
into a virtual grid, e.g. aTDrawGrid
in virtual mode, which will retrieve the cells content via an Event from a separated data list. It will be much faster than this IMHO. I useTDrawGrid
with thousands of rows with instant access, e.g. for our log viewer - For instance, a 280 MB log file is opened in less than one second on my laptop. Under Seven, it takes more time to display the "Open file" dialog window than reading and indexing the 280 MB content. – Arnaud BouchezTDrawGrid
you may learn VirtualTreeView. It's not just a tree view as it sounds to be ;-) – TLamaTStringGrid
. It's not possible to compareTDrawGrid
withVirtualTreeView
just because they looks different, but both will be more efficient thanTStringGrid
, that's for sure. I've suggested youVirtualTreeView
from my personal preference and because you can do much, much more things than withTDrawGrid
. But if you really need just an old looking grid with very basic functionality,TDrawGrid
might be sufficient for you. – TLamaTStringGrid
in this case - is it for displaying or editing data? If you only need to display data, then evenTListView
should give you more than sufficient performance gains, and if you use it in "virtual mode" you will gain even more. However, I have to agree with @TLama aboutVirtualTreeView
- it is simply the best component out there. I've stopped usingTStringGrid
a long time ago and I've never looked back. – LightBulbDBGrid
- which 'loads' only the visible rows - might also better perform. – NGLN