DataGrid - Commit new row only when Enter-key is pressed

Dec 9, 2008 at 1:51 PM
Hi all,

The default scenario in the DataGrid is that the changes in a row get committed when the Enter-key is pressed, or when the user leaves the edited row (using tabs, mouse, etc). I want to commit only when the Enter-key is pressed. How would I go about this?

Thanks in advance,
Dec 9, 2008 at 4:21 PM
You can listen to DataGrid.PreviewKeyDown and flag if the EnterKey has been pressed while the DataGrid is in an editing state.  You will also have to attach to RowEditEnding and if the flagged enter key is pressed continue the commit, otherwise set e.Cancel = true.
Dec 10, 2008 at 5:47 AM
Hi vinsibal,

I did think of that approach, but is seems such a roundabout way to achieve my goal. It would be a nice feature for the DataGrid if the developer could specify on which actions changes to the data should be committed (hint, hint ;-)