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

Validation using DataView's columnerror

3 Answers 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bernhard
Top achievements
Rank 1
Bernhard asked on 19 Jul 2016, 07:28 AM

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

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 19 Jul 2016, 10:29 AM
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.
0
Bernhard
Top achievements
Rank 1
answered on 19 Jul 2016, 01:55 PM

Thanks Hristo.

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

Regards,
Bernhard

0
Hristo
Telerik team
answered on 21 Jul 2016, 12:56 PM
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.
Tags
GridView
Asked by
Bernhard
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Bernhard
Top achievements
Rank 1
Share this question
or