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

gridview Row error

3 Answers 390 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mihai Velicu
Top achievements
Rank 1
Mihai Velicu asked on 30 Mar 2010, 07:47 PM
In row validating event I check some values and if is a wrong value I wrote

e.Row.ErrorText = string.empty
if my condition .is not OK
    e.Row.ErrorText = "BlaBla"
    e.Cancel = true
end if

All very nice but after i validate and  this new row is inserted in datagrid , I still have the red error sign besides of the "Click here to add new row" .

What I'm doing wrong ?

Mihai



3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 02 Apr 2010, 02:54 PM
Hello Mihai,

Thank you for contacting us.

I tried to reproduce the problem on my side but without success. Therefore I would ask you to prepare a very simple project that demonstrates the issue so that I can debug it and further help you.

I am looking forward to your reply.


Kind regards,
Georgi
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mihai Velicu
Top achievements
Rank 1
answered on 05 Apr 2010, 05:01 PM
Hi !
I don't know how to attach a project.

But Anyway !
In a new winform project drag a rad gridview on the form. Don't change anything in properties .

Add this code :

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadData()
    End Sub

    Private Sub LoadData()
        Dim dt As New DataTable("Test")

        Dim dc As New DataColumn("Col1")
        dc.DataType = System.Type.GetType("System.Int32")
        dt.Columns.Add(dc)
        dc = New DataColumn("Col2")
        dc.DataType = System.Type.GetType("System.String")
        dt.Columns.Add(dc)

        Dim dr As DataRow = dt.NewRow()
        dr("Col1") = 1
        dr("Col2") = "String1"
        dt.Rows.Add(dr)

        dr = dt.NewRow()
        dr("Col1") = 2
        dr("Col2") = "String2"
        dt.Rows.Add(dr)

        RadGridView1.DataSource = dt
    End Sub


    Private Sub RadGridView1_RowValidating(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.RowValidatingEventArgs) Handles RadGridView1.RowValidating
        Dim objRow As GridViewRowInfo = e.Row
        If objRow Is Nothing Then
            Return
        End If
        Dim drView As DataRowView = objRow.DataBoundItem
        If drView Is Nothing Then
            Return
        End If

        e.Row.ErrorText = String.Empty

        If drView.Item("Col2") Is DBNull.Value OrElse drView.Item("Col2").ToString().Trim = String.Empty Then
            e.Row.ErrorText = "Col2 Field must be filled in !"
            e.Cancel = True
            Return
        End If
        Return

    End Sub

Add a new row.
Add a numeric value in column 1. Left click with the mouse on another row.Come back on the new row and press Enter. This row is at the end of  the grid and there is still a red error mark on the line with "Click here to Add new row ".
If I put e.cancel = true It should cancel adding the new row to the table, isn't it ? Because in this case it still adds this new row to the grid even I put e.Cancel = true.

Regards,
Mihai








0
Martin Vasilev
Telerik team
answered on 08 Apr 2010, 12:12 PM
Hi Mihai Velicu,

Thank you for the additional details.

Despite the fact that GridViewNewRowInfo has an ErrorText property (it comes from inheritance), it cannot be used in the same way as with GridViewDataRowInfo. That is because, the "add new row" has some specifics. plus the validation process is different. That means that we still do not support error provider scenarios for adding new row elements, and there is no easy way to show the data error icon and text. We are aware about this limitation and we will improve this feature for some of the next releases.

As to attaching your projects, you need to use the support ticketing system. Attaching code and assemblies in the Forums is forbidden, although you can paste code, if needed.

Let me know if you have any other questions.

Greetings,
Martin Vasilev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Mihai Velicu
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Mihai Velicu
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or