0

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?

starmucks
  • 43
  • 1
  • 9
  • The problem is that I filtered the data and then call the method ToList(). When I edit data in the DataGridView is still updated?! I can't understand why! I'm not tied to the data through ToBindingList(). – starmucks Dec 31 '17 at 17:32
  • Really nobody knows the answer to this question. Maybe the question is not clear? – starmucks Jan 01 '18 at 07:19

0 Answers0