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

Add New Row to databound grid

1 Answer 342 Views
GridView
This is a migrated thread and some comments may be shown as answers.
pierre-jean
Top achievements
Rank 1
Veteran
Iron
pierre-jean asked on 12 Oct 2017, 12:56 PM

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

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 13 Oct 2017, 10:10 AM
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.
Tags
GridView
Asked by
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Answers by
Dimitar
Telerik team
Share this question
or