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

Problem with error Icon on Cell Validating

2 Answers 215 Views
GridView
This is a migrated thread and some comments may be shown as answers.
pierre-jean
Top achievements
Rank 1
Veteran
Iron
pierre-jean asked on 11 Jan 2020, 02:35 PM

Hello

I have a grid view where I perform  Cell validation and I change the Error Icon

This grid has EnterKeyMode set to EnterMovesToNextRow

When I enter an invalid value in a cell and validate by clicking on another cell I get the proper response, i.e. Error Message and modified error Icon

but When I validate the entry with a "Return" I get the error message but the error Icon remains the default and is not changed to my custom error Icon

Also, when I validate with Enter I get a "beep" but not when I validate by selecting another cell
Here is my code for changing the error Icon

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

   Private Sub gvPrize_ViewCellFormatting(sender As Object, e As CellFormattingEventArgs) Handles gvPrize.ViewCellFormatting
        'Change Row Error Icon
        If e.RowIndex > -1 Then
            If TypeOf e.CellElement Is GridRowHeaderCellElement Then
                Dim aCell As GridRowHeaderCellElement = CType(e.CellElement, GridRowHeaderCellElement)
                Dim ip As ImagePrimitive = CType(aCell.Children(0), ImagePrimitive)
                If ip.Image IsNot Nothing Then ip.Image = My.Resources.v2_error_16
            End If
        End If
    End Sub

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

2 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 14 Jan 2020, 12:24 PM

Hi,

Thank you for your information, it was greatly appreciated. By using your code and adding CellValidating logic (which was copied from the Data validation article) I have managed to reproduce the scenario that you have described. 

I would like to note that if you cancel the CellValidating event,the ViewCellFormatting event will not fire if you remain on the same row (e.g after pressing Enter). Therefore the modified error icon will not be applied. In order to trigger the ViewCellFormatting you could use InvalidateRow() method after canceling the CellValidating as follows. This will force the ViewCellFormatting event to be fired for this particular row:

Private Sub RadGridView1_CellValidating(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellValidatingEventArgs) Handles RadGridView1.CellValidating
    Dim column As GridViewDataColumn = TryCast(e.Column, GridViewDataColumn)
    If TypeOf e.Row Is GridViewDataRowInfo AndAlso column IsNot Nothing AndAlso column.Name = "CategoryName" Then
        If String.IsNullOrEmpty(DirectCast(e.Value, String)) OrElse DirectCast(e.Value, String).Trim() = String.Empty Then
            e.Cancel = True
            DirectCast(e.Row, GridViewDataRowInfo).ErrorText = "Validation error!"
            e.Row.InvalidateRow()
        Else
            DirectCast(e.Row, GridViewDataRowInfo).ErrorText = String.Empty
        End If
    End If
End Sub

Please do not hesitate to ask if you have further 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.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 15 Jan 2020, 12:21 PM

Hello Dimitar

Thanks a lot for your answer and for the time spent in reproducing the problem

Your suggested solution works perfectly

Thanks again

Tags
GridView
Asked by
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Answers by
Dimitar
Telerik team
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Share this question
or