This is a migrated thread and some comments may be shown as answers.

RadGridView: Allowing users to leave cell if validation fails

1 Answer 364 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mimi
Top achievements
Rank 1
Mimi asked on 15 Jan 2019, 08:33 PM

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;
                        }
                    }
                   


1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 16 Jan 2019, 09:46 AM
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.
Tags
GridView
Asked by
Mimi
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or