Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF DataGrid Add, Update and Delete using MVVM

Tags:

mvvm

wpf

datagrid

I am looking for a sample code/Article which would demonstrate WPF DataGrid in action with MVVM pattern to add, updated and delete record from database.

I have a specific requirement for allowing user to insert new record using DataGrid not a new child form.

If anyone can recommend good resource or provide a sample for that particular task it would be great help for me.

like image 614
fawad Avatar asked Sep 06 '10 06:09

fawad


2 Answers

Here on CodeProject is an article about WPF DataGrid + MVVM pattern:

http://www.codeproject.com/KB/WPF/MVVM_DataGrid.aspx

like image 181
Slauma Avatar answered Sep 24 '22 18:09

Slauma


I don't know of any good articles on the subject, but I don't see the problem; as long as you bind to an ObservableCollection or ListCollectionView containing objects whose class has a default constructor (I don't think there are other restrictions), the DataGrid will handle things pretty well. The collection you bind to must have some way of adding new items, which is why you need to bind to an ICollection or IEditableCollectionView - the latter is preferred, as it has specific options for controlling the creation of items - see AddNew, CanAddNew etc, which the DataGrid works well with.

like image 42
Alex Paven Avatar answered Sep 23 '22 18:09

Alex Paven