Hi, I'm trying to change the XamDataGrid's behavior, but I can't seem to get it working the way I want it to. The requirement is that, when a user is editing a row, the user should not be able to leave the row while it is invalid (and so it should stay in edit mode). However, the user should still be able to switch between cells because sometimes an object's validation state is determined by multiple properties (e.g. the From and Till properties in the sample).
The data object implements IDataErrorInfo and IEditableObject in order to support these functionalities.
Can you get my attached sample project working with these requirements?
Please take a look at Readme.txt, which is part of the Visual Studio solution. It contains more detailed technical information.
One more side question; when I set the wrong value for Icon (Red), and then press ESCAPE to roll back, I see some binding errors about PreDropDownAreaTemplate and PostDropDownAreaTemplate in the Visual Studio output window. Why is this?
Kind regards, Stefan
Hey Yanko,
Thanks for helping! Your approach does indeed handle the record edit mode, but by solving it this way the IEditableObject functionality is broken. The EndEdit is called even when incorrect values are entered, so this means there is no more possibility to roll back these values.
There are 2 more requirements that I didn't mention before because I already got them working myself, which are now no longer working. (1) The user must be able to cancel the row editing, putting back the original values. This is the IEditableObject functionality I mentioned before. And (2) when the row is committed and the data object is valid, the row will be saved. You commented out the part that simulates the save functionality, but I believe that this requirement still works. If I uncomment the save-code it still seems to work anyway.
So, any thoughts on that IEditableObject functionality?
Regards, Stefan
Hello Stefan,
Thank you for contacting Infragistics. I have been looking into your requirement and I managed to achieve it by handling to events of the XamDataGrid: ‘EditModeEnding’ and ‘XamDataGrid_RecordDeactivating’. In the first one I am getting the latest edited cell in the XamDataGrid and after that canceling the deactivating of a particular record if there is not acceptable data :
private void XamDataGrid_EditModeEnding(object sender, EditModeEndingEventArgs e)
{
activeCell = e.Cell;
}
private void XamDataGrid_RecordDeactivating(object sender, RecordDeactivatingEventArgs e)
if ((e.Record as DataRecord).DataError != null)
e.Cancel = true;
this.dataGrid1.ActiveCell = activeCell;
this.dataGrid1.ExecuteCommand(DataPresenterCommands.StartEditMode);
I am attaching a modified version of your sample application(EditableObjects2.zip) that shows my approach.
Let me know, if you need any further assistance on this matter.