TelerikDeveloper.com

TelerikDeveloper.com

sgray128 1/28/2014 12:32:37 PM

Winforms - Saving Grid Data

There are two ways to save edited grid data. You can trap UserAddingRow, UserDeletingRow, and the CellEndEdit event.

The other way is to put a save button on the form and loop through the grid's data source as show below and make the CRUD changes enmasse.



Dim oDT As DataTable = Me.RadGridView1.DataSource
Dim oDTchanges As DataTable = oDT.GetChanges
 
If Not IsNothing(oDTchanges) Then
    For Each oRow As DataRow In oDTchanges.Rows
        Select Case oRow.RowState
            Case DataRowState.Added
                Try
                    'get the new data
                    Dim strSopnumbe As String = oRow("sopnumbe")
 
                    'data access code to save new rows
 
                Catch ex As Exception
                    FPCommon.ErrorHandler.globalErrorHandler(ex, True)
                End Try
            Case DataRowState.Deleted
                Dim intRowID As Int32 = oRow("RowID", DataRowVersion.Original)
                'data access code to delete the row
 
            Case DataRowState.Modified
                Try
                    'get the changed data
                    Dim intRowID As Int32 = oRow("RowID")
                    Dim strSopnumbe As String = oRow("sopnumbe")
 
                    'data access code to update the row
 
                Catch ex As Exception
                    FPCommon.ErrorHandler.globalErrorHandler(ex, True)
                End Try
        End Select
    Next
 
    oDT.AcceptChanges()
End If