Completed
Last Updated: 29 Jul 2014 12:32 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 10 Jun 2014 08:07
Category: GridView
Type: Bug Report
0
FIX. RadGridView - ArgumentException - "Column does not belong to table" when changing the DataSource in the CellEndEdit event
To reproduce:

Private _createDataTable As Object
Private _BoxValue As String

Sub New()

    InitializeComponent()

    RelCalculateValues()
    Me.RadGridView1.BestFitColumns(Telerik.WinControls.UI.BestFitColumnMode.AllCells)
End Sub

Private Sub RadGridView1_CellEndEdit(sender As Object, e As GridViewCellEventArgs) _
    Handles RadGridView1.CellEndEdit
    If e.RowIndex < 0 OrElse e.ColumnIndex < 0 Then Exit Sub
    If e.Value = _BoxValue Then Exit Sub
    If e.Column.Name <> "AllowedWane" Then Exit Sub
    Dim fTester As Decimal
    Dim rRow As Telerik.WinControls.UI.GridViewDataRowInfo = e.Row
    Dim iRowID As Int32
    iRowID = rRow.Cells("ID").Value
    If iRowID < 0 Then Exit Sub

    Select Case e.Column.Name
        Case "AllowedWane"
            If Decimal.TryParse(e.Value, fTester) = False Then
                rRow.Cells(e.Column.Name).Value = _BoxValue
                Exit Sub
            Else
                Select Case e.Column.OwnerTemplate.MasterTemplate.Owner.Name
                    Case RadGridView1.Name
                        RelCalculateValues(Me.RadGridView1)

                End Select
            End If
    End Select
End Sub

Private Sub RelCalculateValues(ByVal rgvAsete As Telerik.WinControls.UI.RadGridView)
    Dim dtJakauma As New DataTable
    Dim drJakauma As DataRow
    dtJakauma.Columns.Add("ID", GetType(Int32))
    dtJakauma.Columns.Add("Dimensions", GetType(String))
    dtJakauma.Columns.Add("Pcs", GetType(String))
    dtJakauma.Columns.Add("Percents", GetType(String))
    dtJakauma.Columns.Add("Price", GetType(String))
    dtJakauma.Columns.Add("UsageFactor", GetType(String))
    dtJakauma.Columns.Add("CubicMeters", GetType(String))
    dtJakauma.Columns.Add("EdgeLimit", GetType(String))
    dtJakauma.Columns.Add("AllowedWane", GetType(String))
    dtJakauma.Columns.Add("Length", GetType(String))

    For i As Int32 = 0 To 5
        drJakauma = dtJakauma.NewRow
        drJakauma("ID") = 0
        drJakauma("Dimensions") = "Dimensions_" & i
        drJakauma("Pcs") = "Pcs_" & i
        drJakauma("Percents") = "Percents_" & i
        drJakauma("Price") = "Price_" & i
        drJakauma("UsageFactor") = "UsageFactor_" & i
        drJakauma("CubicMeters") = "CubicMeters_" & i
        drJakauma("EdgeLimit") = "EdgeLimit_" & i
        drJakauma("AllowedWane") = "AllowedWane_" & i
        drJakauma("Length") = "Length_" & i
        dtJakauma.Rows.Add(drJakauma)
    Next
    rgvAsete.DataSource = dtJakauma
    rgvAsete.BestFitColumns(Telerik.WinControls.UI.BestFitColumnMode.AllCells)
End Sub


Workaround: set the RadGridView.DataSource to null/Nothing before setting it to the new DataTable.
0 comments