本文介绍了如何使BindingSource知道其DataSource中的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个:someBindingSource.DataSource = someDataSource;我也做:someDataSource = foo(); foo() new 另一个不同数据源的数据源。foo() does new for another data source with different data.我不认为每次数据源更改时都进行分配是正确的,即:I don't think it's correct to do the assignment every time the data source changes, i.e:someDataSource = foo();someBindingSource.DataSource = someDataSource;所以有一种方法使 someBindingSource 意识到 someDataSource 中的变化?so is there a way to make someBindingSource aware of change in someDataSource?推荐答案如果数据源实现 IBindingList ,然后将通知 BindingSource 将数据源添加或删除。一个很好的实现方法是 BindingList< T> 。If the data source implements IBindingList inteface, then the BindingSource will be informed of adding or removing items to the data source. A good implementation to use is BindingList<T>.如果数据源的项目实现 INotifyPropertyChanged ,那么 BindingSource 也将被通知项目的更改。Also if the items of the data source implement INotifyPropertyChanged, then the BindingSource also will be notified of changes on items.在上述情况下 ListChanged 事件将被提升。In above cases ListChanged event will be raised. 注意 注意,如果您分配了 someBindingSource.DataSource = someThing; 然后 someThing = new SomeThing(); ,因为 someBindingSource.DataSource 指向上一个对象,没有任何变化,没有任何通知。在将新值分配给 DataSource 之后,会引发事件数据源 一个 BindingSource ,所以在 someThing = new SomeThing(); 之前,如果执行 someBindingSource.DataSource = someThing; 然后 DataSourceChanged 将被提升。 Pay attention, If you assign someBindingSource.DataSource = someThing; and then someThing = new SomeThing();, since someBindingSource.DataSource is pointing to previous object, there is no change and there would be no notifications. DataSourceChanged event will be raised after you assign a new value to DataSource of a BindingSource, so after someThing = new SomeThing(); in previous situation if you perform someBindingSource.DataSource = someThing; then the DataSourceChanged will be raised. 这篇关于如何使BindingSource知道其DataSource中的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 15:11