One of the benefits is that if you manually manipulate the values in the DataGridView, the changes will be reflected in the underlying data. (EDIT: obviously this also works with a regular DataSource binding.)
Another advantage is that you get the opportunity to add an entry to the underlying data (at least if it is a List
) by clicking on an extra empty field and editing the values. This will add a new item without any additional code to write.
This detailed data binding guide can help shed more light on data binding capabilities in general.
EDIT:
Another difference is that manipulation of the underlying data, for example adding an item to the list, will not be displayed in the DataGridView
, even if you again set the DataSource
property, which will work, for example, in ComboBox
. But reassigning a new instance of BindingSource
will do the trick.
So, if you have a List of Faces:
List<pers> list = new List<pers>(); BindingSource bs = new BindingSource(); bs.DataSource = perlist; dataGridView1.DataSource = bs;
and then you want to add a new element to the list in the code, just create a new instance of BindingSource
, reassign it to DataGridView.DataSource
list.Add(new pers()); bs = new BindingSource(); bs.DataSource = perlist; dataGridView1.DataSource = bs;
and the new item will be displayed
source share