问题描述
我在Google上搜索并发现了很多建议,但这些建议似乎都已经使用了好几年了,但都没有帮助。
I googled and found a lot of advice, but it all seemed several years old and none of it helped.
我有一个8列的字符串网格,一次我收到了几百行,但要花2秒钟以上才能填充(我使用GetTickCount进行了比较)。
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).
我尝试了 StringGrid.Perform( WM_SETREDRAW,0,0)
(最后是 0,1
)。我尝试在更新时设置
。两者都没有用。
可见:= False
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.
没有 BeginUpdate()
方法。
有什么建议吗? Delphi XE2启动器。如果愿意,我愿意使用FOSS第三方VCL字符串网格。经过测试。
Any advice? Delphi XE2 starter. I would be willing to use a FOSS 3rd party VCL string grid if it is tried & tested.
[使用TDrawGrid更新... ... TDrawGrid没有属性 Cells,例如它的兄弟TStringGrid。您的代码必须计算出显示数据的位置,然后它必须在网格的画布上绘制数据的表示形式。
[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 :-(
使用VirtualTreeView-听起来不错足够快。我只是没有任何子节点。(更新++,我只是在虚拟树视图非常快。添加一百万个节点仅需700毫秒。那么速度上就没有问题。但是仅使用字符串网格就不错了。特别是在用户
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.
或者,stringgrid仅高20行,也许我可以处理滚动条单击并清除并在用户滚动时重新填充这20行?
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更新]我从TStringGrid更改为TListView,其中的代码具有 Beginupdate())
,但是差异可忽略不计。操作,我忘了虚拟模式-brb。
[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?
推荐答案
向其他人添加建议的虚拟字符串网格插入 TdzVirtualStringGrid
,该插件基于 TDrawGrid
构建,并添加事件以返回要显示的字符串。我将其用于非常大的网格,并且工作正常。
Adding to others suggesting a virtual string grid I'd like to plug TdzVirtualStringGrid
which builds on a TDrawGrid
and adds events to return the strings to display. I am using it for very "large" grids and it works fine.
下载。
(您需要从同一文件中获取更多文件存储库,这只是主要组件源代码。)
(You need more files from the same repository, this is just the main component source code.)
编辑:通过来自同一存储库的更多文件,我的意思是,该组件使用dzlib中的其他单元库,因此您可能应该检查整个shebang并将其添加到程序的搜索路径中(其中有很多有用的东西,因为每当我遇到需要更通用解决方案的内容时就添加到其中)提取组件所依赖的那些单位。 dzlib是根据MPL许可的。
By "more files from the same repository" I mean, that this component uses other units from the dzlib library, so you should probably check out the whole shebang and either add it to your program's search path (there is a lot more useful stuff in there, because I add to it whenever I come across something that needs a more generalized solution) or just extract those units which the component depends on. dzlib is licensed under MPL.
这篇关于如何快速将许多行添加到TStringGrid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!