This is a migrated thread and some comments may be shown as answers.

When is RadGridView actually loaded?

4 Answers 1679 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Asle
Top achievements
Rank 1
Asle asked on 21 Oct 2020, 01:43 PM
Hi, in my WPF application I display a large grid with data using RadGridView.
The grid is relatively large, about 150 columns x 750 rows, so after it is loaded I set a layout (sorting, some row filters and hide some columns).

I use the RadGridView.Loaded-event to trigger the layout adjustments.

The first time I open the grid after starting the application, the layout is not applied when opening the grid - because the grid is empty eventhough the Loaded-event was fired. From the second time opening the grid and onwards, the grid have data and the layout is applied. 

The Loaded-event seem not to guarantee that the grid is done loaded. Are there other ways to make sure the RadGridView has loaded all data and is ready for manipulation?

It also takes notably longer time to open it the first time after starting the application, making me to believe that the application loads DLLs etc, could that have any relation?

I've tried the other events available for RadGridView (https://docs.telerik.com/devtools/wpf/controls/radgridview/events/overview#radgridview), but the result is the same.
Im using 2020.1 version.

4 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 26 Oct 2020, 07:46 AM

Hello Asle,

The Loaded event of RadGridView comes from the WPF native FrameworkElement class and in general is not very reliable when it comes to data loading and especially for rendering. The event simply tells that the control is added to the UI and it is ready for rendering in its most basic state. RadGridView requires some additional actions to happen, so the data could be still loading in the Loaded event handler. To achieve your requirement, you can use the DataLoaded event of RadGridView, but keep in mind that the even will fire on different occasions, like filtering for example. If this doesn't help, can you tell me what kind of adjustments you need to do and why this should happen after the data is loaded? Note that the sorting, filtering and columns visibility can be adjust before the data is loaded. Additionally, if you use information from the data source to decide what kind of settings should be applied, you can use the collection passed to the ItemsSource beforehand.

About the performance, the dlls loading usually should not be noticeable. Also, there is a small amount of time required when you initialize a control for the first time, because its styles are loaded, but this should not be observable too. I would recommend you to check the Performance Tips and Tricks article and see if you can apply anything from there that will improve the performance. The most common reason for slowness in RadGridView is placing it in a panel that measures its children with Infinity. This means that the panel provides as much space as required to render the entire control (or controls) placed inside of it. For example, StackPanel does this. 

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Asle
Top achievements
Rank 1
answered on 05 Nov 2020, 07:40 PM
Hi,

Thank you for the reply Martin.

The reason we set the layout after initialization of the grid is because we use dynamic data which is given to the RadGridView as ITypedList. We therefore do not know the number of columns and which types of columns until the grid is loaded - this can vary per user. 

Users may save adjustments done in the grid as a "layout" (filters, visibility of columns ++) and then apply a given layout as default to use when opening the grid the next time. We have a function which search through the grid columns etc to set filters again, but this do not work when the grid is not finished loading. And it is only the first time the RadGridView is used in each session this happens. From the second time opening a new instance of the grid it works because then Loaded and DataLoaded events "speaks the truth". Are we approaching this the wrong way?

We have tried the DataLoaded event and the tips and tricks which you listed, but it does not have any effect unfortunately. The first time in each session the RadGridView is used, the DataLoaded event is triggered eventhough it has no or just some content.
0
Martin Ivanov
Telerik team
answered on 10 Nov 2020, 12:09 PM

Hello Asle,

Here is another approach that you can try:

private void RadGridView_Loaded(object sender, RoutedEventArgs e)
{
	Dispatcher.BeginInvoke(new Action(() => 
	{
		// execute the adjustments here   
	}), (DispatcherPriority)3); // here you can test with different dispatcher priorities
}

Using the dispatcher will delay the execution of the code in the action. I hope this helps.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Asle
Top achievements
Rank 1
answered on 10 Nov 2020, 01:48 PM

Thanks again for the reply, now it actually works!

 

By using Dispatcher, it seems that the component gets enough time to load before we apply the layout.

For information to other users; we've decided to use DispatcherPriority.Normal (priority 9) which always seems to work.

Tags
GridView
Asked by
Asle
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Asle
Top achievements
Rank 1
Share this question
or