如何提高DataGridView的绘画性能?
(对不起,英语不好)
重新绘制时,我在 DataGridView
的性能方面遇到了大问题。
我正在使用 DataGridView
显示来自外部应用程序流的日志。来自流的消息以高频率进入(小于 1 毫秒)。如果我在每条新消息到来时立即向 DataGridView 添加新行,则在下一条消息到来之前,DataGridView 没有时间重新绘制自身。
一种可能的解决方案是使用队列来收集消息,并每 100 毫秒使用队列中的消息重新绘制 DataGridView。这很好,但是 DataGridView
在自动滚动到最后一行时会闪烁。 (平滑滚动已禁用)
您能帮助我提高 DataGridView
性能吗?
(sorry for bad English)
I have a big problem with performance of DataGridView
when it re-paints.
I'm using a DataGridView
to show logs from an external application stream. Messages from the stream come in with a high frequency (less than 1 ms). If I add new row to the DataGridView
immediately when each new message comes, the DataGridView
doesn't have time to re-paint itself before the next message comes.
A possible solution is to use a queue to collect messages and re-paint DataGridView
every 100 ms with messages from queue. This is good but the DataGridView
blinks when it auto-scrolls to the last row. (Smooth scroll is disabled)
Can you help me to improve DataGridView
performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我最近遇到了
DataGridView
的一些缓慢问题,解决方案是以下代码它为
DataGridView
对象打开双缓冲。只需在 DGV 上调用DoubleBuffered()
即可。希望有帮助。编辑:我可能已经把这个关闭了,但我现在无法搜索原始代码,所以这只是为了强调代码不是我的。
I recently had some slowness issues with
DataGridView
and the solution was the following codeIt turns double buffering on for
DataGridView
objects. Just callDoubleBuffered()
on your DGV. Hope it helps.Edit: I might've gotten this off SO, but I can't search for the original right now so this is just to emphasize that the code isn't mine.
您是否为网格视图启用了双缓冲?
看看
DataGridView 在一个屏幕上的重绘性能非常糟糕我的两个屏幕(
如果您还没有想出一些想法)
Have you enabled double buffering for the grid view?
have a look at
Horrible redraw performance of the DataGridView on one of my two screens
if you haven't already for some ideas
没有反射的干净解决方案是:
然后转到 myForm.designer.cs 并将类型从 DataGridView 更改为 DataGridViewDoubleBuffered 。
Clean Solution without reflection is:
Then go to myForm.designer.cs and change a type from DataGridView to DataGridViewDoubleBuffered .
另请阅读 MSDN 文章:
缩放 Windows 窗体 DataGridView 控件的最佳实践
Also read MSDN article:
Best Practices for Scaling the Windows Forms DataGridView Control
处理大量数据时,
DataGridView
控件可能会消耗大量内存,除非您小心使用它。在内存有限的客户端上,您可以通过避免使用内存成本较高的功能来避免部分开销。您还可以使用虚拟模式自行管理部分或全部数据维护和检索任务,以便为您的场景自定义内存使用情况。更多详情您可以访问dapfor。 com
When working with large amounts of data, the
DataGridView
control can consume a large amount of memory in overhead, unless you use it carefully. On clients with limited memory, you can avoid some of this overhead by avoiding features that have a high memory cost.You can also manage some or all of the data maintenance and retrieval tasks yourself using virtual mode in order to customize the memory usage for your scenario. More detail you can visit dapfor. com
我使用这个解决方案并修复了锯齿。
使用反射,因此也在代码中导入它
i use this solution and saw bit fixed.
Reflection is used so import this too in code