On the form (in the constructor) I have a DataGridView control and a BindingSource. As DataSource for the BindingSource selected my Order class. For DataGridView - BindingSource. I load data like this:
context.Orders.Load();
orderBS.DataSource = context.Orders.Local.ToBindingList();
All is working well. I edit data in a separate form and pass it an instance of the Order class (orderBS.Current as Order). In this form I save the changes - context.SaveChanges(). Go back and DataGridView is updated. Now I want to make search field. When you click on the button "Search" I'm doing the following:
bindingSource.DataSource = context.Orders.Where(x => x.Contains(txtBox.Value)).ToList();
Now it turns out orderBS tied just to the List. The data is normally filtered. Just as I give the Order instance. Open the form and edit - the DataGridView is updated!!! Why? I do not call ToBindingList().
I found discussion of this problem here. Bradley Smith responded thus:
You can use a BindingList or BindingSource to get this functionality instead, but your Person class will still need to support INotifyPropertyChanged or else you will only get synchronisation when items are added/removed to/from the list, not when the list items themselves change.
But my Order class is very simple and does not support INotifyPropertyChanged. Why DataGridView is updated?