正确的方式有一个DataGridView直观地反映变化的数据源 [英] Correct way to have a DataGridView visually reflect changes in its DataSource
本文介绍了正确的方式有一个DataGridView直观地反映变化的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设一个的DataGridView
有数据源
属性设置为数据视图
实例。
Say a DataGridView
has its DataSource
property set to a DataView
instance.
DataGridView dgv;
DataTable dt;
// ... dt gets populated.
DataView dv = dt.DefaultView;
dgv.DataSource = dv;
// ... dt gets modified
// The DataGridView needs to update to show these changes visually
// What goes here?
我知道你可以设置 dgv.DataSource
到空
,然后重新设置为 DV
。但是,这似乎是pretty的怪异。我敢肯定,有几个其他的方式了。但是,什么是正确的,正式的方式做到这一点?
I know you could set dgv.DataSource
to null
, then back to dv
. But that seems pretty weird. I'm sure there are a couple of other ways, too. But what's the correct, official way to do this?
推荐答案
在正确的办法就是为数据源实现 IBindingList的
,返回真
为 SupportsChangeNotification
,并出具的ListChanged
事件。但是,AFAIK,一个数据视图
的确实的这...
The correct way is for the data-source to implement IBindingList
, return true
for SupportsChangeNotification
, and issue ListChanged
events. However, AFAIK, a DataView
does this...
这篇关于正确的方式有一个DataGridView直观地反映变化的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文