GridView programmatically grouped performance

0 Answers 103 Views
GridView
Luigi
Top achievements
Rank 3
Bronze
Iron
Iron
Luigi asked on 02 May 2022, 09:41 AM

Hi
I need to represent a list of columns  whose number is multiplied for the cardinality of a list of other elements.
For istance I have a list of "Sources": [S1, S2], and for every sources I have a fixed number of values [V1, V2, V3].
The columns table wil be:
S1                   | S2

V1 | V2 |V3    | V1 | V2 V3

I achieved that with the following code:
 

		private void SetTableColumns(ObservableCollection<StatisticaTableViewPerClasse> elementi
			, IEnumerable<string> sorgentiNames
			, string columnClassHeader)
		{
			GridAnalisiStatisticaTable.Columns.Clear();
			GridAnalisiStatisticaTable.ColumnGroups.Clear();
			if (elementi.Count() > 0)
			{
				//var sorgenti = elementi.GroupBy(e => e.Sorgente.Id,
				//				e => e.Sorgente.Name,
				//				(id, name) => name).Select(s => s.FirstOrDefault());
				foreach (var sorgenteName in sorgentiNames)
				{
					var groupName = GROUPNAME + sorgenteName;
					var group = new GridViewColumnGroup()
					{
						Header = sorgenteName,
						Name = groupName,
						
					};
					GridAnalisiStatisticaTable.ColumnGroups.Add(group); 
					//GridAnalisiStatisticaTable.Columns.Add(new GridViewDataColumn()
					//{
					//	Header = Utility.LoadString(ResourcesKeys.SorgenteColumnHeader),
					//	DataMemberBinding = new Binding("Sorgente.Name"),
					//	ColumnGroupName = groupName
					//});
					GridAnalisiStatisticaTable.Columns.Add(new GridViewDataColumn()
					{
						Header = columnClassHeader,
						DataMemberBinding = new Binding("ClasseHeader"),
						ColumnGroupName = groupName
					});
					GridAnalisiStatisticaTable.Columns.Add(new GridViewDataColumn()
					{
						Header = Utility.LoadString(ResourcesKeys.DistribuzioneProbabilitàHeader),
						DataMemberBinding = new Binding($"Values[{sorgenteName}].DistribuzioneValue")
						{
							StringFormat = "N2"
						},
						ColumnGroupName = groupName
					});
					GridAnalisiStatisticaTable.Columns.Add(new GridViewDataColumn()
					{
						Header = Utility.LoadString(ResourcesKeys.ProbabilitàCumulativaHeader),
						DataMemberBinding = new Binding($"Values[{sorgenteName}].CumulativaValue")
						{
							StringFormat = "N2"
						},
						ColumnGroupName = groupName
					});
				}
			}
		}
Where the GridView is defined as:

<t:RadGridView x:Name="GridAnalisiStatisticaTable" Grid.Row="1"
					   RowIndicatorVisibility="Collapsed"
					   AutoGenerateColumns="False"
						GroupRenderMode="Flat"
					   ShowGroupPanel="False"
						IsPropertyChangedAggregationEnabled="False"
					   ItemsSource="{Binding Statistiche}"/>
And the listed class is:


public class StatisticaTableView
	{
		public StatisticaTableView(KeyValuePair<decimal, double> entry, StatisticType type)
		{
			switch (type)
			{
				case StatisticType.DistribuzioneProbabilità:
					DistribuzioneValue = entry.Value;
					break;
				case StatisticType.ProbabilitàCumulativa:
					CumulativaValue = entry.Value;
					break;
				case StatisticType.LivelliPercentili:
					break;
				case StatisticType.DistribuzioneTemporale:
					break;
				default:
					break;
			}
		}
		public double DistribuzioneValue { get; set; }
		public double CumulativaValue { get; set; }
	}
	public class StatisticaTableViewPerClasse
	{
		public StatisticaTableViewPerClasse(KeyValuePair<decimal, double> entry, decimal classRange, StatisticType type, string sorgenteName)
		{
			Classe = entry.Key;
			ClasseHeader = $"{entry.Key} - {entry.Key + classRange}";
			Values.Add(sorgenteName, new(entry, type));
		}
		public decimal Classe { get; set; }
		public string ClasseHeader { get; set; }
		public Dictionary<string, StatisticaTableView> Values { get; set; } = new();
	}

But the resulting grid (formally correct) has very poor performance, when I scroll the rows, though the rows number is only 30.

I think that the problem comes from the binding with index (DataMemberBinding = new Binding($"Values[{sorgenteName}].DistribuzioneValue")), is there a way to achieve the same result with better  performance?
Thank you
Luigi
Dilyan Traykov
Telerik team
commented on 04 May 2022, 09:16 AM

Hello Luigi,

Thank you for the provided code snippets.

It is possible that the complicated nested binding has some negative effect on performance, but with only 30 rows I do not believe that it should be that noticeable. It is also likely that the UI virtualization mechanism of the control is turned off - possibly because it is placed in a panel that measures it with infinity. Can you please share the structure of your XAML layout in which the RadGridView is placed so that I can check this?

If possible, it would also be of help if you can demonstrate this performance issue in a small sample project so that I can profile it and check its cause as well as try to suggest a viable solution. Do let me know if you would be able to do so.
Luigi
Top achievements
Rank 3
Bronze
Iron
Iron
commented on 08 Sep 2022, 07:02 AM

Hi Dylan
I finally noticed that the scroll is very slow only when I debug. Executing the app from command line the performance is accettable.
But often I'm in debug and I need to scroll the grid, maybe are there any tricks to speed up the operation?

Thank you
Luigi
Dilyan Traykov
Telerik team
commented on 09 Sep 2022, 03:07 PM

Hi Luigi,

Indeed, it is expected for the performance of the application to be noticeably better when ran in Release mode.

To optimize the performance of the control in Debug mode as well, you can apply the modifications suggested in the following article: Tips and Tricks.

If the performance is still unacceptable, please send over a small sample project which demonstrates the degraded performance and I will gladly further investigate its cause and try to suggest a viable solution.

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Luigi
Top achievements
Rank 3
Bronze
Iron
Iron
Share this question
or