Reputation: 6903
I would like to implement a simple WPF with a datagrid and a save button.
when I click save button it will accept changes (row edit,cell edit, new row, delete etc)
I tried RowEditHandler
and CollectionChange
event using observable collections. But I couldnt get a soluton. Can anyone please show me a simple way.
Using dataset (xsd), I was able to achive that simpy by sending datacontext of grid to dataset and using update function.
thanks for help
Upvotes: 3
Views: 7688
Reputation: 177163
The ADO.NET team blog has an example how to bind a Entity Framework Code-First model to a WPF DataGrid which supports adding, deleting and editing entities in the grid and finally saving all changes. It is focussed on a Master-Details scenario but should with a few modifications also work in your even simpler case with only a single DataGrid:
The example is based on EF CTP5 but it will most likely also work without changes with the new EF 4.1 RC version.
The ADO.NET team example uses code-behind files and events. If you prefer to strictly work with the MVVM approach the solution of David Veeneman provided in this answer might be helpful:
It's not a full WPF example but can serve as a foundation how to extend an ObservableCollection in a way that it supports Create-Update-Delete operations with Entity Framework.
Upvotes: 5