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

Cell and Row Validating

3 Answers 259 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Claude
Top achievements
Rank 1
Iron
Veteran
Claude asked on 01 Dec 2020, 01:40 AM

It seems the Cell and Row Validating events only work when editing an existing cell.    

 

They do not work when adding a new row.  The event is called, but the validating code does not work correctly.

Code is fine when updating an existing row. 

 

I can do data validation in the userAddingRow event, but then the ((GridViewDataRowInfo)e.Row).ErrorText = "All Columns Require Data";  produces an error so then you need to use a messagebox.  

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 01 Dec 2020, 05:31 AM

Hello, Claude,

The CellValidating event is fired when you try to exit the current cell and navigate to another one either when the editor is active or when the cell is not in edit mode. In both cases, the event is expected to be fired. If the cell is in edit mode, the editor's value will not be committed to the cell until the value is validated. Hence, cancelling the CellValidating event will keep the editor active and the user wouldn't be allowed to exit this cell. A sample approach how to validate the Value in the CellValidatingEventArgs is demonstrated here: https://docs.telerik.com/devtools/winforms/controls/gridview/editors/data-validation 

On the other hand, the RowValidating event can be used the same way to prevent the user from exiting the current row. However, the editor will be closed in this case and the value will be committed to the underlying data source. Cancelling the RowValidating event wouldn't allow the user to navigate to another cell.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Claude
Top achievements
Rank 1
Iron
Veteran
answered on 01 Dec 2020, 05:23 PM

I understand that, but that did answer my question.   Why will the 2 validating events will not work correctly when adding a new row to the grid?

 

Updating a row is fine, but adding a row it does not work.  The event fires in both cases, but the validating code only works when updating an existing row and NOT WHEN YOU ARE ADDING A NEW ROW.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Dec 2020, 05:33 AM

Hello, Claude,

Indeed, the CellValidating event is not suitable for validating the user's input in the new row. Make sure that its code is executed only for data rows.

RadGridView exposes several end-user events two of which you will find useful in the context of the new row: UserAddingRow and UserAddedRow. These events are fired when the user commits the new row (by pressing the Enter key or by clicking somewhere in the grid). As the name of the UserAddingRow implies, it allows for preventing the new row from being committed as a data row. This may be useful in case some of the data entered by the end-user is invalid according to some custom requirements. An example is demonstrated in the following help article: https://docs.telerik.com/devtools/winforms/controls/gridview/rows/new-row#user-events 

I believe that this event would fit your scenario. Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
Claude
Top achievements
Rank 1
Iron
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Claude
Top achievements
Rank 1
Iron
Veteran
Share this question
or