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

GroupDescriptors disappear after changing ItemsSource to empty/null

11 Answers 588 Views
GridView
This is a migrated thread and some comments may be shown as answers.
MB
Top achievements
Rank 1
MB asked on 29 Oct 2010, 03:02 PM
1) Bind collection to GridView
2) Group on a column
3) set the collection to a new empty collection, or set grid itemssource = null

You should notice that the columns are still on the grid, but the group is removed.

We are trying to persist grouping options across different sets of data, when hitting an empty dataset, the grouping is lost.

The _Grouped and _Grouping events are not fired, however a manual check shows that the GroupDescriptors are indeed cleared.

(This is using Q3 Beta but it was the same behaviour in previous versions)

11 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 29 Oct 2010, 03:27 PM
Hi,

This is by design. You can save the group descriptors somewhere before resetting the data and add them to the GroupDescriptors collection after the data has come.

All the best,
Veselin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Martin
Top achievements
Rank 1
answered on 25 Feb 2011, 08:55 PM
Just ran into this myself, curious as to why this design choice was made? I would think the grids meta data (column, group descriptors, etc) would persist across different items sources?

Marty
0
Yavor Georgiev
Telerik team
answered on 26 Feb 2011, 05:49 PM
Hello Marty,

 When the ItemsSource of a RadGridView is changed, there is no guarantee that the columns and descriptors defined will be applicable to the type of the new data items. That is why, rather than risking exceptions in the LINQ runtime, they are cleared.

Greetings,
Yavor Georgiev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Ivan
Top achievements
Rank 1
answered on 24 Apr 2013, 11:46 PM
How ???
0
Rossen Hristov
Telerik team
answered on 25 Apr 2013, 11:11 AM
Hello,

By calling the Collection<T>.Clear method of the respective collection.

Kind regards,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Lukas
Top achievements
Rank 1
answered on 08 Jul 2015, 12:10 PM
Well... Yes, it is not guaranteed that the group descriptors still work. But wouldn't that be my fault? This is quite contra-intuitive behavior, especially if I set the group descriptors in XAML.
0
Dimitrina
Telerik team
answered on 08 Jul 2015, 03:22 PM
Hi,

Thank you for sharing your feedback.

Regards,
Dimitrina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Shawn
Top achievements
Rank 1
answered on 05 Oct 2015, 08:16 PM

Hi guys, doesn't seem like telerik was much help on this at all.  I encountered the same issue in my project where I was setting the ColumnGroupDescriptor of a RadGrid GroupDescriptor through my XAML.  At some point the screen would rebind the RadGrid to null and then back to a valid list.  At this point my grouping was completely lost.

 

I hate programatically setting binding but in this instance, I passed the RadGrid to my ViewModel as a method parameter from a trigger event and in the corresponding method linked to that trigger, I set the itemsource and a new GroupDescriptor.  This worked and allowed the grouping to reappear each time the Grid was set to null and then back to a list.I had to remove the GroupDescriptor definition in the XAML as well.

Sample of C# code to set Group Descriptor Programatically:

 

GroupDescriptor descriptor = new GroupDescriptor();
descriptor.Member = "NAME_OF_MY_COLUMN";
descriptor.SortDirection = ListSortDirection.Ascending;
thisAllocationGrid.GroupDescriptors.Add(descriptor);
0
Tom
Top achievements
Rank 1
answered on 17 Nov 2017, 03:42 PM

This is a bug. Plain and simple.

XAMLdefines the Grouping/Filtering. If the 'new' Item source has a different shape then ofcourse there should be an exception. 

The real reason Telerik do not want to change this behaviour is backwards compatibility, which is totally understandable.

Like Shawn, I have moved all XAML definitions of group/filtering to the ViewModel where I build the QueryableCollectionView. Thumbs down.

0
Dilyan Traykov
Telerik team
answered on 12 Oct 2020, 12:56 PM

Hello Carsten,

I'm happy to hear that you've found a suitable solution and would like to thank you for sharing it with our community.

Should you require any further assistance, please let us know.

Regards,
Dilyan Traykov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

Tags
GridView
Asked by
MB
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Martin
Top achievements
Rank 1
Yavor Georgiev
Telerik team
Ivan
Top achievements
Rank 1
Rossen Hristov
Telerik team
Lukas
Top achievements
Rank 1
Dimitrina
Telerik team
Shawn
Top achievements
Rank 1
Tom
Top achievements
Rank 1
Carsten
Top achievements
Rank 1
Veteran
Dilyan Traykov
Telerik team
Share this question
or