Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2325
Action RecordUpdatingAction.CancelUpdateDiscardChanges does not retain value
posted

I have the following code that I use to validate certain cells that are editable:

        private void GrdMaint_OnRecordUpdating(object sender, RecordUpdatingEventArgs e)
        {
            //
            var cells = e.Record.Cells;
            var editFields = _Vm.EditColumns(_currentStep);
            var msg = string.Empty;
            var hasError = false;

            foreach (var item in cells)
            {
                var tmpMsg = string.Empty;
                
                if (!editFields.Contains(item.Field.Name)) continue;

                if (_Vm.PassesValidation(_currentStep, item.Field.Name, item.Value, out tmpMsg)) continue;

                hasError = true;
                msg += string.Format(" {0}",tmpMsg);
            }

            if (hasError)
            {
                System.Media.SystemSounds.Asterisk.Play();
                        
                lblValidationMessage.Content = msg;
                lblValidationMessage.Visibility = Visibility.Visible;

                GrdMaint.ExecuteCommand(DataPresenterCommands.StartEditMode);
               
                e.Action = RecordUpdatingAction.CancelUpdateDiscardChanges;
                e.Handled = true;                
            }
            else
            {
                e.Action = RecordUpdatingAction.ProceedWithUpdate;
                lblValidationMessage.Content = msg;
                lblValidationMessage.Visibility = Visibility.Collapsed;                
            }
        }

The problem I am having is that when the user enters in a wrong value the previous value is not retained nor is the field back into edit mode.  Am I doing this correctly?  Is there a better way to do cell validation?

Parents
No Data
Reply
  • 14517
    Verified Answer
    Offline posted

    Hello Jerovsek,

    When using Record Updating Actions your underlying object should implement IEditableObject in order to track and reject the changes. For more information on the IEditableObject interface please see http://msdn.microsoft.com/en-us/library/system.componentmodel.ieditableobject(v=vs.110).aspx.

    I have tested using CancelUpdateDiscardChanges on an object implementing IEditableObject and the behavior is as expected, when I cancel the update the value reverts back to its original value.  I have attached my sample I used to test this, please verify whether this works for you.

    To learn more on various ways of editing and validating data in the XamDataGrid please see http://help.infragistics.com/doc/WPF/2014.1/CLR4.0/?page=xamDataGrid_Editing_Data.html.

    Let me know if you have any questions.

    Sincerely,

    Valerie

    Developer Support Supervisor - XAML

    Infragistics

    www.infragistics.com/support

    WpfApplication1.zip
Children