Skip to content

SyncfusionExamples/How-to-load-Async-Data-in-OnDemandLoading-in-WinForms-DataGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to load Async Data in OnDemandLoading in WinForms DataGrid

In WinForms DataGrid (SfDataGrid), SfDataPager.OnDemandLoading event does not support the async and await processes. Therefore, if you are using the await keyword to call a method, it may not work properly. However, you can overcome this issue by setting the sfDataGrid.DataSource in the OnDemandLoading event and then refreshing the SfDataPager.PagedSource.

sfDataPager1.OnDemandLoading += SfDataPager1_OnDemandLoading;
BusyIndicator BusyIndicator = new BusyIndicator();

private async void SfDataPager1_OnDemandLoading(object? sender, Syncfusion.WinForms.DataPager.Events.OnDemandLoadingEventArgs e)
{
    var results1 = await _orderInfos.GenerateOrders();
    sfDataPager1.LoadDynamicData(e.StartRowIndex, results1.Skip(e.StartRowIndex).Take(e.PageSize));
    BusyIndicator.Show(this.sfDataGrid1.TableControl);
    Thread.Sleep(1000);
    if (sfDataGrid1.DataSource == null)
        sfDataGrid1.DataSource = sfDataPager1.PagedSource;
    (sfDataPager1.PagedSource as PagedCollectionView).Refresh();
    BusyIndicator.Hide();
}

SfDataGrid_DataPager_AsyncLoad.gif

Take a moment to peruse the WinForms DataGrid - Paging documentation, where you can find about the basic details about paging the DataGrid.

About

The demo shows how to load Async Data in OnDemandLoading in WinForms SfDataGrid.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages