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

Automatically clearing RadGridView SortDescriptors on ReBinding ItemSource

5 Answers 213 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Allen
Top achievements
Rank 1
Allen asked on 26 Jun 2012, 03:19 PM
Is there a way to cleanly get a RadGridView to clear its SortDescriptors everytime the ItemSource is refreshed with a new data source?

My problem is that I am loading different dataset (different columns) into a RadGridView and when there is sorting on one of the data set, after binding a new dataset to the same RadGridView, it is obviously remembering the SortDescriptor and throwing an error because the column it is trying to sort on no longer exists in the new set of data it is being bound to.

Also I am trying to do this in a clean MVVM (WPF) way so calling RadGridView.SortDescriptors.Clear() in the code behind of my WPF form is not the approach I'm looking for.

Any ideas?

5 Answers, 1 is accepted

Sort by
0
Eli
Top achievements
Rank 1
answered on 01 Nov 2012, 04:07 PM
Hello.

I would like the know the answer as well.

Thank you.
0
Rossen Hristov
Telerik team
answered on 02 Nov 2012, 11:42 AM
Hi,

RadGridView will clear all of its descriptors if the new items source is not compatible with the old one, i.e. has different properties/columns.

You can see this in the project that I have attached.

Regards,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Mark
Top achievements
Rank 1
answered on 14 Nov 2012, 06:36 PM
Hey Rossen, 

Is this new behaviour?  We have recently updated to the Q2 0912 release and have just realized an issue that may be related to his functionality.

We are using the Persistence Framework to persist state when the gridview is unloaded.  However, if we set ItemSource to null before the unloaded handler fires then the SortDescriptor collection is empty and does not get persisted as expected.  Our persistence code has been working for a long time and we have only recently noticed the breakage, which is why I ask if it is new.

If this is new, is there a way to turn this off and get the behaviour we used to have?  If it's not new, do you have any idea what else may have changed to cause the issues we are seeing?

Thanks,
Mark.
0
Rossen Hristov
Telerik team
answered on 15 Nov 2012, 08:06 AM
Hi,

Yes, this is the way the logic works right now.

Can you persist the sort descriptors before you set the ItemsSource to null? Why do you need to set the ItemsSource to null in the first place? What do you expect will happen if you set it to null?

Regards,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Mark
Top achievements
Rank 1
answered on 15 Nov 2012, 03:07 PM
Hi Rossen,

Yes, persisting the sort and group descriptors before setting it to null is the workaround I implemented yesterday.  In general we do not set it to null, however there are a couple of cases where we set it to null on hidden controls to try to keep memory overhead low as we have rather large datasets.  In these cases, I wanted the objects to be available for garbage collection if necessary.  I admit I am not totally sure it matters, but I feels like the right thing to do.

Thanks,
Mark.
Tags
GridView
Asked by
Allen
Top achievements
Rank 1
Answers by
Eli
Top achievements
Rank 1
Rossen Hristov
Telerik team
Mark
Top achievements
Rank 1
Share this question
or