Add New Row to databound grid

2 posts, 0 answers
  1. pierre-jean
    pierre-jean avatar
    144 posts
    Member since:
    Apr 2011

    Posted 12 Oct 2017 Link to this post

    I have a grid that is populated from a BindingList (I am working with the EntityFramework)

    The CellValueChanged event does apply the changes to the underlying database

    But When I add a new row, the UserAddedRow (which is fired) does not add the row to the underlying database (and does not generate an error)

    Despite long hours of research I have not found the solution to add a new row to my table by typing it's value in the "New Row" of the grid

    Thanks in advance

    The code snipet:

    'Populate the Grid
     Dim mArena As New mArena(context)
            Dim allArenas As BindingList(Of Arena) = mArena.GetArenasByShowId(idShow)
            gvArena.AutoGenerateColumns = True
            gvArena.DataSource = allArenas

       Public Function GetArenasByShowId(ByVal idShow As Integer) As BindingList(Of Arena)
            Try
                Dim Query = (From aArena As Arena In context.Arenas
                             Where aArena.idShow = idShow
                             Order By aArena.Name)
                Return New BindingList(Of Arena)(Query.ToList())
            Catch ex As Exception
                RaiseEvent msg("F", ex.Message)
                Return Nothing
            End Try
        End Function

    'Grid Events
        Private Sub gvArena_CellValueChanged(sender As Object, e As GridViewCellEventArgs) Handles gvArena.CellValueChanged
            Try
                context.SaveChanges()
            Catch ex As Exception
                RaiseEvent msg("F", "CellValueChanged: " & ex.Message)
            End Try
        End Sub

        Private Sub gvArena_UserAddedRow(sender As Object, e As GridViewRowEventArgs) Handles gvArena.UserAddedRow
            Try
                gvArena.EndEdit()
                context.SaveChanges()
            Catch ex As Exception
                RaiseEvent msg("F", "AddedRow: " & ex.Message)
            End Try
        End Sub

  2. Dimitar
    Admin
    Dimitar avatar
    2934 posts

    Posted 13 Oct 2017 Link to this post

    Hi Pierre,

    The proper place to update the data source is the RowsChanged event: Tracking changes in RadGridView.

    I hope this will be useful. 

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top