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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Async On Demand Loading

Thread ID:





129665 Mar 27,2017 03:01 PM UTC Mar 30,2017 07:07 PM UTC WPF 1
Tags: SfTreeGrid
Frido Dombek
Asked On March 27, 2017 03:01 PM UTC

Hi,I have to load data asynchronously from the web and want to display it in a SfTreeGrid using 'On Demand Loading'. 
However I couldn't figure out a way to populate the tree on demand when I'm calling and awaiting async functions to load the data.

As an example, if modify your OnDemandLoading Example and add a await Task.Delay(1) call to the code, it won't populate the tree with tree nodes anymore.

/// <summary>
/// Gets the reportees.
/// </summary>
/// <param name="bossID">The boss ID.</param>
/// <returns></returns>
public async Task<IEnumerable<EmployeeInfo>> GetReportees(int bossID)
    List<EmployeeInfo> list = new List<EmployeeInfo>();
    int loc = FindID(bossID);
    if (loc > -1)
        await Task.Delay(1);
        while (loc < this.EmployeeDetails.Count && this.EmployeeDetails[loc].ReportsTo == bossID)
    return list;

I then await this function in:
async void AssociatedObject_RequestTreeItems(object sender, TreeGridRequestTreeItemsEventArgs args)

How can I populate the SfTreeGrid on demand with data that is loaded asynchronously?

Regards and Thanks,

Muthukumar Kalyanasundaram [Syncfusion]
Replied On March 30, 2017 07:07 PM UTC

Hi Frido, 

Thank you for contacting Syncfusion support. 

We have checked your query. We are able to reproduce the reported query in our end. You can overcome this problem by handling the AutoResetEvent. For your reference, we have attached the code snippet and sample in the below location, 

Code Snippet: 
System.Threading.AutoResetEvent autoreset = new System.Threading.AutoResetEvent(false); 
async void AssociatedObject_RequestTreeItems(object sender, TreeGridRequestTreeItemsEventArgs args) 
    if (args.ParentItem == null) 
        //get the root list - get all employees who have no boss  
        args.ChildItems = viewModel.EmployeeDetails.Where(x => x.ReportsTo == -1); //get all employees whose boss's id is -1 (no boss) 
    else //if ParentItem not null, then set args.ChildList to the child items for the given ParentItem. 
    {   //get the children of the parent object 
        EmployeeInfo emp = args.ParentItem as EmployeeInfo; 
        if (emp != null) 
            Task t = Task.Run(() => 
private async void GetChildItem(TreeGridRequestTreeItemsEventArgs args) 
    EmployeeInfo emp = args.ParentItem as EmployeeInfo; 
    args.ChildItems = await viewModel.GetReportees(emp.ID); 

Please let us know if you have any query. 

Muthukumar K 


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