Do I need a BindingSource AND a BindingList for WinForms DataBinding?
Binding to an IList<Person>
will only give you one-way binding; changes to the list or list items will not be reflected in the DataGridView
. You can use a BindingList
or BindingSource
to get this functionality instead, but your Person
class will still need to support INotifyPropertyChanged
or else you will only get synchronisation when items are added/removed to/from the list, not when the list items themselves change.
If you want to avoid a dependency on System.Windows.Forms
, you could use ObservableCollection<Person>
instead; this supports the necessary change notifications and can therefore be used as a two-way binding source.
If you use BindingList<T>
then changes that you make through the underlying list will be reflected in the data bound controls because BindingList raises an event when the list is changed. Most other collections do not.
If you use a normal collection as the data source then changes that you make through other data bound controls (or through the BindingSource) will still be reflected, but changes to the underlying collection directly will not.