Validation using DataView's columnerror

4 posts, 0 answers
  1. Bernhard
    Bernhard avatar
    3 posts
    Member since:
    Jul 2013

    Posted 19 Jul Link to this post

    Hi.

    I'd like to validate the data of a grid and display validation errors. I'm working with a DataSet and use the column errors of it.
    As suggested here (http://www.telerik.com/forums/how-to-set-errortext-when-adding-a-record) I set the Grid's DataSource as a DataView but still no errors are displayed. When setting the error texts manually it works though.

    Are there any other prerequisites for the Dataview's columnerrors or is it just not supported by RadGridView?

    Sample code:

        Friend WithEvents grd_report_ As Telerik.WinControls.UI.RadGridView

            For i As Integer = 0 To row.Table.Columns.Count - 1
                Select Case row.Table.Columns(i).ColumnName
                    Case "some column"
                        If error_condition Then
                            row.SetColumnError(i, "error")
                        End If
                    Case ...
               End Select
            Next
            ...
            'doesn't display any errors
           grd_report_.DataSource = ds.Tables(TAB_REPORT).DefaultView()   

            'setting ErrorTexts works
            For Each r As GridViewRowInfo In grd_report_.Rows
                Dim drv = CType(r.DataBoundItem, DataRowView)
                For i As Integer = 0 To r.Cells.Count - 1
                    r.Cells(i).ErrorText = drv.Row.GetColumnError(i)
                    'has to be set in CellFormatting event apparently!?!?
                    'If Not String.IsNullOrEmpty(r.Cells(i).ErrorText) Then
                    '    r.Cells(i).Style.BackColor = Color.Red
                    '    r.Cells(i).Style.NumberOfColors = 1
                    '    r.Cells(i).Style.DrawFill = True
                    'End If
                Next
            Next

    Best regards,
    Bernhard

  2. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 19 Jul Link to this post

    Hello Bernhard,

    Thank you for writing back.

    Following the solution suggested in the other forum thread, I created a VB version of the project and you can find it attached.

    If I understand correctly you would like to validate the data in your grid after you performed the data binding. In this case, you can subscribe to the DataBindingComplete event and iterate your rows. Where necessary you can set the ErrorText property of the row.

    Additionally, you may check the following resources: 
    I hope this helps. Please let me know if you need further assistance.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Bernhard
    Bernhard avatar
    3 posts
    Member since:
    Jul 2013

    Posted 19 Jul in reply to Hristo Merdjanov Link to this post

    Thanks Hristo.

    Is it possible to display the exclamation sign on the cells where errors occur instead of the header column?

    Regards,
    Bernhard

  5. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 21 Jul Link to this post

    Hello Bernard,

    Thank you for writing.

    Yes, it is possible. Basically, you would need to follow the same approach with the difference that the error image instance has to be created in the inherited cell elements and added to their Children collection.

    I am sending you a modification of the project demonstrating the suggested approach.You can further extend it to handle all cases according to your local setup.

    I hope this helps. Please let me know if you need further assistance.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
Back to Top