views:

22

answers:

2

Hi,

I have binded a list with Editable WPF DataGrid

I want to get only the modified Items from the WPF Data Grid for updation.

Please let me know how to do this.

A: 

Well there is a RowState property on your data row (there is also a RowChanged event), but make sure you need this. Am I under the wrong assumption that databinding automatically figures out which rows need to be updated?

ThatSteveGuy
A: 

I have my WPF datagrid app set up as so:

1) Manually defined all the columns, set their bindings and for each binding specified that it notifies on source updates

2) Added an event handler for the datagrid's SourceUpdated event

3) In the event handler I have only the following code:

this.updatedItems.Add(BindingOperations.GetBindingExpression(e.TargetObject, e.Property).DataItem as MyClass); 

updatedItems is a HashSet<> and MyClass is the type of objects bound to the datagrid's ItemsSouce.

4) When the user clicks on the save button I simply enumerate the hashset. Hashset is nice, because it only contains unique values. So if a row is edited multiple times or even if multiple cells in the same row are edited, the hashset will still only contain a single entry for the object.

Marko
Hi Marko, SourceUpdated event is not triggering when i modify the DataGrid manually. I have also set NotifiesOnSourceUpdates = true for all my binded columns. Can you please correct me if i am wrong or if i missed something
ksvimal
Hmm. Are you using the DataGrid that comes with .NET4 or the DataGrid from the WPF Toolkit? I don't know if the two have any behaviour differences in this case (I'm using the .NET4 one). Make sure the bindings also have UpdateSourceTrigger=PropertyChanged. By manually updating you mean typing in the values or setting the values in code?
Marko
Hi Marco, I have missed UpdateSourceTrigger=PropertyChanged now its working. Thanks
ksvimal