I have a:
someBindingSource.DataSource = someDataSource;
And I also do:
someDataSource = foo();
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;
so is there a way to make someBindingSource
aware of change in someDataSource
?
If the data source implements
IBindingList
inteface, then theBindingSource
will be informed of adding or removing items to the data source. A good implementation to use isBindingList<T>
.Also if the items of the data source implement
INotifyPropertyChanged
, then theBindingSource
also will be notified of changes on items.In above cases
ListChanged
event will be raised.Note
someBindingSource.DataSource = someThing;
and thensomeThing = new SomeThing();
, sincesomeBindingSource.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 toDataSource
of aBindingSource
, so aftersomeThing = new SomeThing();
in previous situation if you performsomeBindingSource.DataSource = someThing;
then theDataSourceChanged
will be raised.