3

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

1 Answer 1

5

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:

http://blogs.msdn.com/b/adonet/archive/2011/03/08/ef-feature-ctp5-code-first-model-with-master-detail-wpf-application.aspx

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:

Entity Framework 4 and WPF

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.