How to load async Data in OnDemandPaging 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 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();
}
Take a moment to peruse the WinForms DataGrid - Paging documentation, where you can find about the basic details about paging the DataGrid.
Conclusion
I hope you enjoyed learning about how to load async Data in OnDemandPaging in WinForms DataGrid.
You can refer to our WinForms DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms DataGrid example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!