Problem with error Icon on Cell Validating

3 posts, 0 answers
  1. pierre-jean
    pierre-jean avatar
    143 posts
    Member since:
    Apr 2011

    Posted 11 Jan Link to this post

    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. Dimitar
    Admin
    Dimitar avatar
    24 posts

    Posted 14 Jan Link to this post

    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.
  3. pierre-jean
    pierre-jean avatar
    143 posts
    Member since:
    Apr 2011

    Posted 15 Jan in reply to Dimitar Link to this post

    Hello Dimitar

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

    Your suggested solution works perfectly

    Thanks again

Back to Top