大数据更新时DataGridView滞后一秒
我有一个大约 400 行和 10 列的 DataGridView。当用户第一次显示此表时,它会从服务器接收所有数据并填充该表。 DGV 使用 DataTable 作为数据源,在更新 DataTable 时,我使用 row.BeginEdit/EndEdit 和 AcceptChanges,但是当更新视图本身时,它会滞后一秒钟,同时更新所有 DGV。我想知道是否有一种方法可以使这种顺利进行,例如,如果用户滚动数据并且数据更新,它不会中断滚动。或者,如果用户在屏幕上移动显示并更新,它不会中断。有没有简单的方法可以做到这一点?如果不是,是否有办法阻止 DGV 更新视图,直到所有事件结束,以便在用户停止滚动、拖动等之前不会重新绘制视图?
I have a DataGridView with about 400 rows and 10 columns. When the user first displays this table, it receives all of the data from the server and populates the table. The DGV uses a DataTable as it's data source, and when updating the DataTable I use row.BeginEdit/EndEdit and acceptChanges, but when the View itself is updated it lags for a second while all of the DGV is being updated. I am wondering if there is a way to make this smooth, so that for example, if the user is scrolling through the data and it updates, it won't interrupt the scrolling. Or if the user is moving the display around the screen and it updates, it won't interrupt. Is there an easy way to do this? If not, is there away to prevent the DGV from updating the view until all events have ended so it won't be repainted until the user stops scrolling, dragging, etc ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
过去我发现缓慢问题可能与自动调整大小属性有关。这里还有一些更多的想法:针对缓慢的 DataGridView 的快速修复
In the past I've found that slowness issues can be related to the auto-sizing properties. Here are some more ideas as well: Quick fixes for slow DataGridView
我想到的第一个想法是使用
后台工作人员
。然后,当您的BackgroundWorker
更新时,它不会占用主线程,即 GUI 线程。The first idea that comes to my mind is to use a
BackgroundWorker
. Then, while yourBackgroundWorker
updates, it doesn't occupy the main thread, that is, your GUI thread.尝试运行调试器/分析器来确定哪个部分是导致速度变慢的实际原因。一旦你弄清楚哪一行是罪魁祸首,回答这个问题就会更容易。
Try running debugger/profiler to determine which part is the actual cause for slow down. Once you figure out which line(s) are the culprit it will be easier to answer this question.