One of the advantages is that if you manipulate values in the DataGridView manually then the changes will be reflected in the underlying data.
(EDIT: apparently this also works with normal DataSource binding.)
another advantage is that you get the possibility to add an entry to the underlying data (at least if it is a List
) by clicking on the extra empty field and edit the values. This will add a new item without any additional code for you to write.
This Detailed Data Binding Tutorial may help to shed more light on the capabilities of data binding in general
EDIT:
One more difference is that manipulation of the underlying data, like adding an item to a List will not be reflected in the DataGridView
even if assigning the DataSource
property again which would work for example in a ComboBox
.
But a reassigning of a new instance of a BindingSource
will do the trick.
So if you have a List of persons:
List<pers> list = new List<pers>();
BindingSource bs = new BindingSource();
bs.DataSource = perlist;
dataGridView1.DataSource = bs;
and later on want to add a new item to the list in the code, just create a new instance of BindingSource
, reassign it to the DataGridView.DataSource
list.Add(new pers());
bs = new BindingSource();
bs.DataSource = perlist;
dataGridView1.DataSource = bs;
and the new item will be display
INotifyPropertyChanged
. – Poussette