Update data of SfDataGrid after DataSource is updated

Hi Technical Support;

I am using WinForms control SfDataGrid (Vesion 19.3.0.53), in Visual Studio 2019 (

Version 16.11.7) .Net5.0 Framefork, EntityFrameforkCore5.0.12, SQLExpress DB, on the following way:

           LabclinicFiscal dbcontext = new LabclinicFiscal();

           sfDataPagerInvoiceReq.DataSource = dbcontext.OrderRequest.ToList();

            sfDataPagerInvoiceReq.PageSize = 30;

            sfDataGridInvoiceReq.DataSource = sfDataPagerInvoiceReq.PagedSource;

            sfDataGridInvoiceReq.LiveDataUpdateMode = LiveDataUpdateMode.AllowDataShaping;

           .......

       After adding a new record (or updating record) to the Database table OrderTequest, using EF service to              create a new record, and the end refresh DataGrid:

       this.sfDataGridInvoiceReq.View.Refresh();

       I can not see new row data in sfDataGrid. After restarting the Form of SfDataGrid, a new row is visible.  

      How to resolve this issue.

     If I repeat SfDataGrid initialization  at the and of EF Add service:

        sfDataPagerInvoiceReq.DataSource = dbcontext.OrderRequest.ToList();

            sfDataPagerInvoiceReq.PageSize = 30;

            sfDataGridInvoiceReq.DataSource = sfDataPagerInvoiceReq.PagedSource;

            sfDataGridInvoiceReq.LiveDataUpdateMode = LiveDataUpdateMode.AllowDataShaping;

             this.sfDataGridInvoiceReq.View.Refresh();

        It is working fine.

        Please advise me on the right approach.

         Kind regards,

        Zoran  

        }




1 Reply

VS Vijayarasan Sivanandham Syncfusion Team December 17, 2021 11:07 AM UTC

Hi Zoran Babic,

You are obtaining the DataSource from the Database table OrderTequest. The Datatable was converted to a List collection, which was then bound to SfDataGrid. SfDataGrid does not bound directly with the database table. So, SfDataGrid will not refresh the UI automatically while adding/removing records in the Database table. As you mentioned earlier update, You must update the collection which is directly bound to the SfDataGrid manually to update the changes in the UI.

Regards,
Vijayarasan S

Loader.
Up arrow icon