WPF Datagrid updates

R

ryanbreakspear

Hi,

I have a WPF datagrid bound to a List<CustomObject>. The object
implements INotifyPropertyChanged & IEditableObject.

When a row in the datagrid has been updated I want to write the
changes to the database. I also need to audit the changes made, so
want access to the old and new properties. Using the RowEditEnding
event, the values of the object are still the old ones (I need the new
values as I already have a reference to the old ones). I can access
the new values using the EditingElement in the CellEditEnding event,
but I want to do this at a row level, and don't want to have to write
code for each column.

I can change the behaviour of the RowEditEnding, either by setting the
UpdateSourceTrigger=PropertyChanged on the binding, or by calling
DataGrid.CommitEdit, but both of these remove the ability to cancel
the edit if an error occurs.

Basically I want access to old and new values, and choose whether to
Commit or Cancel changes. Any ideas would be appreciated.

Thanks in advance

Ryan
 
M

mick

ryanbreakspear said:
Hi,

I have a WPF datagrid bound to a List<CustomObject>. The object
implements INotifyPropertyChanged & IEditableObject.

When a row in the datagrid has been updated I want to write the
changes to the database. I also need to audit the changes made, so
want access to the old and new properties. Using the RowEditEnding
event, the values of the object are still the old ones (I need the new
values as I already have a reference to the old ones). I can access
the new values using the EditingElement in the CellEditEnding event,
but I want to do this at a row level, and don't want to have to write
code for each column.

I can change the behaviour of the RowEditEnding, either by setting the
UpdateSourceTrigger=PropertyChanged on the binding, or by calling
DataGrid.CommitEdit, but both of these remove the ability to cancel
the edit if an error occurs.

Basically I want access to old and new values, and choose whether to
Commit or Cancel changes. Any ideas would be appreciated.

Thanks in advance

I'm only just learning WPF myself and have not used the Datagrid yet
but doesnt the second example on here do what you want?

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowediting.aspx

mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top