5

I have problem updating DataSource of a DataGridView in WindowsForms application.

I have DataGridView populated by data in List of my own class Skoleni.

private List<Skoleni> setrideneSkoleni; //list of objects

In MainForm() method, I call following:

 bindingDwgSkoleni = new BindingSource(); //create bindingsource
 bindingDwgSkoleni.DataSource = setrideneSkoleni; //set datasource for bindingsource
 dgwSkoleni.DataSource = bindingDwgSkoleni; // set datasource for datagridview

Which sets DataSource for both BindingSource and DataGridView.

Then I add item tosetrideneSkoleni in additional form, the button_Click method contains this:

setrideneSkoleni.Update(); // updates setrideneSkoleni
bindingDwgSkoleni.ResetBindings(false); //should update bindingSource, but DOES NOT

Variable setrideneSkoleni is updated (item is added), but BindingSource is not (checked in debug - list still contains the same items).

I can not simply set DataSource of DataGridView to null and than to new list, because it destroys formatting (hidden columns become visible, sorting is cancelled), I have to use BindingSource to keep the configuration.

Can anyone advice me how to fix this?

Thanks

Zbynek
  • 5,673
  • 6
  • 30
  • 52

1 Answers1

0

Change your List to BindableList. Implement INotifyProperty on Skoleni class.