I still haven't found a solution to this problem: https://www.telerik.com/forums/cellvalidating-event-question
asked
1. When user inputs an invalid value for a cell, we can use ErrorText to show an error message in the RowHeaderColumn. Normally, the ErrorText will be cleared after the user corrects the value. Sometimes the user will just press Esc key to cancel the input value, in this case the CellValidating event won't get fired and the ErrorText will remain shown on the RowHeaderColumn. This behavior will make the user feel confused.
answered
1. CellValidating event occurs only when a cell value is changed. In case when Esc is pressed, the value remains the same and no validation is needed. However, you can handle CellEndEdit event in this case and reset the ErrorText property.
Private Sub grdURLs2_UserAddingRow(sender As Object, e As GridViewRowCancelEventArgs) Handles grdURLs2.UserAddingRow
Try
If TypeOf e.Rows(0) Is GridViewNewRowInfo AndAlso
TryCast(e.Rows(0).Cells(0).ColumnInfo, GridViewDataColumn) IsNot Nothing AndAlso
TryCast(e.Rows(0).Cells(1).ColumnInfo, GridViewDataColumn) IsNot Nothing Then
If e.Rows(0).Cells(0).Value Is Nothing OrElse
String.IsNullOrEmpty(Trim(e.Rows(0).Cells(0).Value)) Then
e.Cancel = True
DirectCast(e.Rows(0), GridViewNewRowInfo).ErrorText = "Empty!"
ElseIf e.Rows(0).Cells(1).Value Is Nothing OrElse
String.IsNullOrEmpty(Trim(e.Rows(0).Cells(1).Value)) Then
e.Cancel = True
DirectCast(e.Rows(0), GridViewNewRowInfo).ErrorText = "Empty!"
ElseIf e.Rows(0).Cells(1).Value IsNot Nothing Then
For Each row In grdURLs2.Rows
If e.Rows(0).Cells(1).Value = row.Cells(1).Value Then
e.Cancel = True
DirectCast(e.Rows(0), GridViewNewRowInfo).ErrorText = "Exists!"
End If
Next
End If
End If
Catch ex As Exception
txtError.Text = ex.Message & " - " & Format(Now, "HH:mm:ss")
End Try
End Sub
Private Sub grdURLs2_CellEndEdit(sender As Object, e As GridViewCellEventArgs) Handles grdURLs2.CellEndEdit
Try
If TypeOf e.Row Is GridViewNewRowInfo Then
DirectCast(e.Row, GridViewNewRowInfo).ErrorText = String.Empty
End If
Catch ex As Exception
txtError.Text = ex.Message & " - " & Format(Now, "HH:mm:ss")
End Try
End Sub
This doesn't work. The CellEndEdit event does not fire.
