views:

105

answers:

1

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?

+1  A: 

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 that IBindingList must 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 Reset value on the ListChanged event (which is what the grid is watching for) by calling ResetBindings on the gridview. This, however, will cause the grid to refresh all of the data, not just what has changed.

Adam Robinson
Both my Company and Investor class support the INotifyPropertyChanged interface so they should be notifying of property updates.Either way, I should be able to tell the datagrid to update somehow though?
Zenox