I have a DataGridView which I am binding like so:
companies = new BindingList<Company>(PersistenceManager.Instance.RetrieveAll<Company>(SessionAction.BeginAndEnd));
bindingSource.DataSource = companies;
potentialInvestorDataGridView.DataBindings.Add("DataSource", bindingSource, "PotentialInvestors");
The problem is when I add to the PotentialInvestors list
Company company = bindingSource.Current as Company;
company.PotentialInvestors.Add ( new Investor ( ) );
The datagrid does not get updated with a new row. I have tried to calling
bindingSource.ResetCurrentItem();
potentialInvestorDataGridView.EndEdit();
potentialInvestorDataGridView.Refresh();
But nothing seems to update the data grid. (If I close the dialog and reopen it the items are now displayed).
What do I need to do to have this updated properly?
Changes will only be propogated if the underlying data source (the result of
PersistenceManager.Instance.RetrieveAll<Company>(...)) supports the notification mechanism. I’m pretty sure that in order for it to work thatIBindingListmust be supported on the data source itself. Do you have a list of the interfaces that the data source implements?Edit
You can manually invoke a
Resetvalue on theListChangedevent (which is what the grid is watching for) by callingResetBindingson the gridview. This, however, will cause the grid to refresh all of the data, not just what has changed.