Refreshing Grid from EF Entity

Jul 1, 2009 at 7:49 PM

I have a MVVM implementation, where the ViewModel is an Entity Framework set (colleciton) bound to a grid. This works fine..until an addition happens.

The add is from a form (Not in grid) , and is persisted to the store correctly.

In my code, I do the following:

  1. Set the dg.ItemsSource = null;
  2. Recreate the viewModel ( this.Model = new MyModel(); )
  3. set the dg.ItemsSource = this.Model ;
  4. Iterate the Model entities - all are there (Debug.WriteLine(item.Name);)
  5. bind the grid with this.dg.Items.Refresh();

The grid does not show the new item :( If I restart the app, the item appears.

Any idea what I am missing here ?




Jul 2, 2009 at 3:28 PM

I think this will give you an idea as to how to proceed.