We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Using 'both' Paging and Binding with VB.Net SfDataGrid not saving edits.

Thread ID:

Created:

Updated:

Platform:

Replies:

145479 Jun 24,2019 07:39 PM UTC Jun 26,2019 01:01 PM UTC WinForms 3
loading
Tags: SfDataGrid
andy
Asked On June 24, 2019 07:39 PM UTC

Hi

Thanks for looking in advance, I'm only a hobbyist so sorry for the code :-)
I'm trying to use both Paging and Binding with VB.Net SfDataGrid however my updates are not being saved back to the DB. I'm using the following code:

Imports System.Data.SQLite
Imports Syncfusion.WinForms.DataGrid.Enums


Module Mod_DataBindingDGV

    Public testTable As New DataTable
    Public bindingSource1 As New BindingSource
    Public adapter As New SQLiteDataAdapter
    Public builder As New SQLiteCommandBuilder(adapter)

    Public Sub GetDataGridView(ByVal sqlString As String)
        Dim sqlCommand As String = sqlString
        Dim SQLconnect As New SQLite.SQLiteConnection With {
    .ConnectionString = Mod_SQLConnections.CreateSQLiteConnectionString
        }

        testTable = New DataTable

        SQLconnect.Open()
        adapter = New SQLiteDataAdapter(sqlCommand, SQLconnect)
        adapter.Fill(testTable)
        bindingSource1.DataSource = testTable
        SQLconnect.Close()

        Form1.SfDataGrid1.SuspendLayout()
        Form1.SfDataGrid1.ResumeLayout()

        Form1.SfDataPager1.DataSource = bindingSource1
        Form1.SfDataPager1.PageSize = 5
        Form1.SfDataGrid1.DataSource = Form1.SfDataPager1.PagedSource
        Form1.SfDataGrid1.AllowEditing = True
        Form1.SfDataGrid1.EditMode = EditMode.DoubleClick
    End Sub


On Form1

AddHandler SfDataGrid1.CurrentCellEndEdit, AddressOf sfDataGrid_CurrentCellEndEdit

    Private Sub sfDataGrid_CurrentCellEndEdit(ByVal sender As Object, ByVal e As CurrentCellEndEditEventArgs)
        MessageBox.Show("The editing is completed for the cell (" & e.DataRow.RowIndex & "," & e.DataColumn.ColumnIndex & ")")
    End Sub

The data is loaded as expected and pages correctly, also the edit completed MessageBox fires.

Thanks Andy





Adhikesevan Kothandaraman [Syncfusion]
Replied On June 25, 2019 01:48 PM UTC

Hi Andy, 

Thanks for using Syncfusion products. 

By default, while editing the cell or row in the SfDataGrid will update the value only in the view. It will not updated to the underlying data source. If you want to update the source once the field is edited in the grid, you have to manually update the value by calling the update method. Please refer to the following code snippet, 

Code Snippet:  
 //To update the data in the DataSource  
 testTable.AcceptChanges() 
 adapter.Update(testTable) 
 

Regards, 
Adhi 


andy
Replied On June 26, 2019 02:24 AM UTC

Hi

I got this to work however I had to remove 'SfDataPager' element from the form completely otherwise the adapter.Update(testTable) has no changes. Also I rearranged the order to:

            adapter.Update(testTable)
            testTable.AcceptChanges()

Not sure how I can use 'SfDataPager ' and still use adapter.Update(testTable).

Thanks
Andy



Adhikesevan Kothandaraman [Syncfusion]
Replied On June 26, 2019 01:01 PM UTC

Hi Andy, 
 
Regret for the inconvenience caused. 
 
By default, the SfDataPager does not support the DataTable as the DataSource. So that can you please try this with the IEnumerable collections. 
Please find the following UG link for the limitation.  
 
Regards, 
Adhi 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon