What I'm trying to achieve is a RadGridView with expanding/collapsing hierarchy rows that uses load on demand data that I get from my server using a REST API call. A separate REST call is started every time a RowSourceNeeded event is fired for a row. The problem is that the GUI thread does not seem to wait for my call and the row tries to expand then immediately collapses again (so basically the whole expand operation does not wait until my data is loaded) after which the grid starts behaving erroneously, which includes;
- the application hangs for a few seconds when I click an expanded hierarchy row
- clicking a hierarchy row makes the whole grid scroll down a bit
Leaving the async API call out for testing purposes and filling the row below with dummy data immediately solves all these problems, so I'm certain it is the cause of these problems.
private async void radGridView1_RowSourceNeededAsync(object sender, GridViewRowSourceNeededEventArgs e)
{
MainJobObject mainJobObject = e.ParentRow.DataBoundItem as MainJobObject;
//make the RESTAPI call here to retrieve the attachments of this job
List<IJobDocument> mainJobObjectAttachments = await FillMainJobObjectWithAttachmentsFromBackend(mainJobObject.JobId);
foreach (IJobDocument attachment in mainJobObjectAttachments)
{
GridViewRowInfo row = e.Template.Rows.NewRow();
row.Cells["MainJobID"].Value = mainJobObject.JobId;
row.Cells["Status"].Value = attachment.StatusObject.Status;
row.Cells["UploadDate"].Value = attachment.StatusObject.UploadDate;
row.Cells["AttachmentID"].Value = attachment.IJobDocumentId;
row.Cells["AttachmentType"].Value = attachment.AttachmentType;
row.Cells["ServisnyTechnik"].Value = attachment.ServisnyTechnik;
row.ErrorText = attachment.Error;
e.SourceCollection.Add(row);
}
}