我可以暂时阻止手动更改 DataGridView 来更新基础数据源吗?
我试图找到另一个像这样的问题,因为它看起来确实像是以前被问过的问题;但我找不到它。
基本上,我有一个 DataGridView
,它绑定到 BindingList
。我知道,一般来说,数据绑定非常好,可以节省大量(我们的开发人员)时间。然而,这个非常大的网格存在一个重大的性能问题。
根据之前的经验,我相当有信心通过在计时器上手动更新仅可见单元格而不是实现INotifyPropertyChanged<,可以大大提高性能。 /code> (这并不是一个真正可行的选项,因为此网格中的许多值每秒更改数十次)或调用
Refresh
。但有一个问题:如果我手动逐一更新网格中的单元格,则每次更新都会触发数据绑定对象相应属性的set
,这加起来会导致性能显着下降。
实际上没有必要进行所有这些 set
调用,因为我放入网格单元格中的值是直接从这些属性中检索的(所以我基本上是读取一个值,然后将其写回到自身)。
如果我可以暂时禁用 DataGridView 的此功能,那就太好了:暂时关闭负责根据网格更新更新底层数据源的功能。然后,当我完成手动更新后,重新打开该功能,以便用户的更新确实影响数据源。
我尝试使用 BindingSource
并将其 DataSource
属性设置为 BindingList
并调用 SuspendBinding
/恢复绑定
;但这似乎不起作用。 set
调用继续进行。
有什么方法可以实现我在这里要做的事情吗?我完全走错路了吗?
I tried to find another question like this one, since it certainly seems like something that may have been asked before; but I couldn't find it.
Basically, I've got a DataGridView
, which is bound to a BindingList<T>
. I understand that in general, data binding is very nice and saves a lot of (our -- developers') time. However, there is a significant performance issue with this grid, which is very large.
Based on prior experience, I am fairly confident the performance can be greatly improved by manually updating just the visible cells in the DataGridView
on a timer rather than implementing INotifyPropertyChanged
(not really a feasible option as many of the values in this grid are changing dozens of times per second) or calling Refresh
. But there's a problem: if I manually update the cells in the grid one by one, every update triggers the set
of the corresponding property for the databound object, which, added up, incurs a significant drain in performance.
It really isn't necessary to make all these set
calls, as the values I'm putting in the grid's cells are retrieved directly from those properties (so I'm basically reading a value and then writing it back to itself).
It would be nice if I could temporarily disable this functionality of the DataGridView
: for a time, turn off the feature responsible for updating the underlying data source based on updates to the grid. Then, when I'm finished updating it manually, turn that feature back on so that the user's updates do affect the data source.
I tried using a BindingSource
with its DataSource
property set to the BindingList<T>
and calling SuspendBinding
/ResumeBinding
; but that didn't seem to work. The set
calls continued to be made.
Is there some way to accomplish what I'm going for here? Am I walking down the wrong path entirely?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我真的不具备直接回答你的问题的知识,但我不久前发现了一篇 MSDN 文章,其中讨论了仅根据需要加载/更新行的方法。
http://msdn.microsoft.com/en-us/library/ms171624。 aspx
这可能是一个可行的解决方案,或者它可能会启发您找出另一种方法。
如果没有,希望很快有人能够给你一个真正的答案o.-
I don't really have the knowledge to answer your question directly, but I found an MSDN article a while back that discussed a method of loading/updating rows only as-needed.
http://msdn.microsoft.com/en-us/library/ms171624.aspx
It might be a viable solution, or it might inspire you to work out another method.
If not, hopefully someone will be able to give you a real answer soon o.-