RadGridView: Allowing users to leave cell if validation fails

2 posts, 1 answers
  1. Mimi
    Mimi avatar
    7 posts
    Member since:
    Dec 2018

    Posted 15 Jan 2019 Link to this post

    In native WinForm forms, a property called AutoValidate can be changed to EnableAllowFocusChange to allow users to continue to other controls if validation fails for an errorProvider.

    I am trying to mimic this behavior with radGridView. Currently, users are unable to move onto other cells or rows, or other controls outside of the gridView until they input correct data into the cell.

    I want to be able to allow the user to work on other things, add rows, edit cells on a new row or an existing row, etc without forcing them to input something just to get rid of the validation. Only at the end of the process would I loop through all controls and cells to see if an error exists, and remind the user before they can continue on.

    This is so that the user doesn't put in erroneous data into the cell just so they can move on. For example, if they do not know what the account code is for an item, they would have to ask someone else and this may take some time. They should be able to work on other things on the form in the mean time.

    I've tried cancelling the editor and calling EndEdit on the current active editor, but this isn't working. Users are still locked in on a cell if validation failed. How do I allow the user to get out of the cell even if an error exists?

    See below on what I have tried:

       if (e.Row is GridViewDataRowInfo)
                        {
                            if (detailValidation.IsEmptyInput(((string)e.Value), out errorMsg) || (!detailValidation.IsValidDecimalFormat(((string)e.Value), out errorMsg)))
                            {
                                e.ActiveEditor.EndEdit();
                                e.Cancel = true;
                                var test = e.ActiveEditor as RadTextBoxEditor;

                                currentCell.BackColor = Color.FromArgb(255, 221, 221);
                                ((GridViewDataRowInfo)e.Row).ErrorText = errorMsg;
                                
                               
                            }
                            else
                            {
                                ((GridViewDataRowInfo)e.Row).ErrorText = string.Empty;
                            }
                        }
                       


  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2907 posts

    Posted 16 Jan 2019 Link to this post

    Hi Mimi,

    You should remove the line which sets the Cancel property to true. This way you will be able to move the focus to other cells event if the value is not correct. 

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top