My Application follows MVVM and uses RadGridView Heavily, and there is a requirement to Preserve user settings which includes Groupings/Filters applied. There are two issues i'm facing at the moment.
1. I don't see a way of preserving Filters/Groupings while following MVVM
2. even if I forget about MVVM and follow the example provided still the Filters are not getting saved. Column Indexes, Column widths seems to be getting saved without a problem but it seems like there is an issue with preserving filters.
Note: I'm using the version 2010.3.1110.40, with .NET framework 4.0, on Windows 7.0
Could you please confirm if there is a known issue in preserving filter settings in the version above, and if not; also let me know if theres way of doing the same while follwing MVVM.
Appriciate a quick response as we have to finalize the requiments in comming week.
Thanx
Asela
22 Answers, 1 is accepted
There should be no problem for you to save the applied filters. You may verify it on our demos that are built against the same version as yours.
In case you need any further assistance, I would need a bit more details about your application. Do you do anything beyond the example for Save and Load RadGridView Layout ?
Maya
the Telerik team

<
telerik:RadGridView
HorizontalAlignment
=
"Left"
x:Name
=
"grdResourceList"
Width
=
"1000"
VerticalAlignment
=
"Stretch"
ItemsSource
=
"{Binding Path=Resources, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
SelectionMode
=
"Single"
SelectedItem
=
"{Binding Path=SelectedResource}"
AutoGenerateColumns
=
"False"
local:CommandBehavior.Event
=
"SelectionChanged"
local:CommandBehavior.Command
=
"{Binding EditCommand}"
local:CommandBehavior.CommandParameter
=
"SelectionChanged"
IsReadOnly
=
"True"
CanUserFreezeColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Resource Code"
DataMemberBinding
=
"{Binding Path=ResourceCode}"
Width
=
"200"
/>
<
telerik:GridViewDataColumn
Header
=
"Resource Name"
DataMemberBinding
=
"{Binding Path=ResourceName}"
Width
=
"400"
/>
<
telerik:GridViewDataColumn
Header
=
"Is Active"
DataMemberBinding
=
"{Binding Path=IsActive}"
/>
<
telerik:GridViewDataColumn
Header
=
"Resource Category"
DataMemberBinding
=
"{Binding Path=ResourceCategory.ResourceCategoryName}"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
Well no i didn't do anything [Grid xaml markup included above], i have included just what i got from the demos, infact like i said if I adjust column width, column index [change the order of the columns] the settings are saved, its the groupings and filters that aren't getting saved. So I assume that i have done everything right since the column width / ordering seems to be getting saved.
Also please answer my other question as well, isn't there a way of saving the layout while following MVVM pattern, your example requires code inside the code behind.
Please let me know if you require any further information.
Asela
I am sending you a sample project implementing the functionality of Save and Load Setting of the GridView Layout so that you can test it locally. I have tested it and everything works quite correct - the filters applied are also saved.
As far as your second issue is concerned, you may try to attach a custom behavior following for loading/ unloading of the application for instance. You may take a look at our demo for an example on defining a particular behavior for the grid.
Maya
the Telerik team
You may find the sample project I mentioned attached in this post.
Maya
the Telerik team

Thanx Maya for the replies, your example works, but don't you still need to pass reference of the grid to the constructor of the RadGridViewSettings class.
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
settings = new RadGridViewSettings(this.playersGrid);
settings.LoadState();
}
well i know how to attach a custom behaviour to loading and unloading event; but what i want know is how to pass a reference to the grid without using the codebehind.
For an exaple in your MainWindow.xaml.cs you have MainWindow_Loaded, Button1_Click, Button2_Click methods; I can get rid of all three methods, and bind em to command propertise in the viewmodel, but my question is how do you pass a refernece to the this.playersGrid to viewModel.
Lets say i have moved the windowloaded method to the view model.
public ICommand MainWindow_Loaded()
{
settings = new RadGridViewSettings(this.playersGrid);
// I cant say this.playersGrid, how do you refer the grid?? cos view model doesn't know anything about it.
}
Hope this is clear enough.
Thanx
Asela
On creating the AttachedBehavior, you may inherit the Behavior class (in your case it may be Behavior<RadGridView>) and use the AssociatedObject for a reference to the grid.
Considering the case with commands, you may use the CommandParameter property and set it to the grid for example.
Kind regards,
Maya
the Telerik team

Managed to preserve filter settings without violating MVVM, however there seems to be a problem with the RadGridViewSettings class. It crashes if there is a column, that this not databound e.g "select" column with a check box. I replaced the commented block with the one below and now it working without a problem; SaveState also needs to be changed to include the null checks.
Thanx
Asela
// LoadState()
// GridViewDataColumn matchingColumn =
// (from column in grid.Columns.OfType<GridViewDataColumn>()
// where column.DataMemberBinding.Path.Path == currentSetting.PropertyName
// select column).FirstOrDefault();
GridViewDataColumn matchingColumn = matchingColumns.Where<GridViewDataColumn>
(x => x.DataMemberBinding.Path.Path == currentSetting.PropertyName).FirstOrDefault();
The GridViewSelectColumn is a GridViewColumn and the IsChecked property of each CheckBox in it is bound to the IsSelected property of each GridViewRow.
Still, I am happy to see the issue has been resolved. Let me know if you need any further assistance.
Maya
the Telerik team

The latest official approach is demonstrated here. You can find the same example in your local copy of our WPF demos.
Greetings,Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

I cannot access both links in your post. Can you attach the sample project in this post? I am using framework 4.0 window 7 with the latest release.
Thanks
Joyce
You can find the example (RadPersistenceFramework/GridView Serialization) in your local installation of the demos. Do you still have troubles opening it ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Got it thanks!
Joyce

Hi,
I am using R2 2017 Radgridview Version(2017.2.614.40), i want to save gridview column position so that if user drag and drop column to other position it should save that position and after reload or restart that column should display on the position where it is dropped.i have tried all examples which is given but nothing works for me....plz help...
I answered your question in the other topic. May I ask you to continue the discussion there? Thank you for your understanding.
Regards,
Vladimir Stoyanov
Progress Telerik

Hi Vladimir,
I am using your RadGridView in my MVVM project and I use the persistance framework for loading and saving the settings of the grid. In your demo you use two buttons for saving and loading the settings and the OnClick-routines have access to the grid. To remove this non MVVM-style solution of loading and storing I want to develop a Behavior that loads and saves the settings.
For loading I use the "Loaded"-event. When this is fired I load all the settings. This seems to work.
But which event(s) can I use to store the settings? Call "save" in the events for arranging columns, sorting colums, defining filters, ... might be very inefficient. Could you please help me.
Regards
Marcus

Hi Vladimir,
one addition to my previous post: I am looking for an event that is fired short before the grid will destroid from the dialog.
Regards
Marcus
Perhaps I am missing something, but you should be able to save the custom settings in the Unloaded event of the RadGridView. Can you give this approach a try and let me know if it is suitable for your scenario?
Should you need any further assistance, may I ask you to provide some more details about the specific scenario and why handling the Unloaded method is not applicable? You can also open a new support ticket and describe the scenario in more detail.
Regards,
Vladimir Stoyanov
Progress Telerik

Hello,
I am using the Unloaded-Event of a RadGridView to store some settings (Column-Width, SortDescriptors, ...) in a stream/file using the PersistenceFramework.
My Problem is: the SortDescriptor seem to be resetted before the Unloaded-Event is fired, so I cannot store it properly.
Can you help me with that plz?
regards,
Tobias
Hello Tobias,
Thank you for the provided information.
While it is difficult to suggest a concrete approach without being able to test the scenario on my end, you can try out a different event for saving the settings (for example the Closing event of the Window). I am attaching a sample project, where I used this approach for your reference. Do check it out and let me know, if it helps.
Should you need any further assistance, can you modify the sample project in order to demonstrate your scenario? Note, that you can send it back in a new support ticket (since projects cannot be attached to forum posts) or let me know what I need to modify in the project in order to replicate the setup on your end. This will hopefully allow me to get a better understanding of the scenario and further assist you.
Regards,
Vladimir Stoyanov
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/.

Hello Vladimir,
thanks for the provided example.
Unfortunately, that is not what I am looking for. My GridView is situated inside a UserControl, which is loaded/unloaded numberless times during the runtime of the program. So I am using the Unloaded-Event of the UserControl or GridView (both with the same issue) to store my settings. I cannot use the Closing event of the MainWindow at this point.
Can you relate to that?
regards,
Tobias
Hello Tobias,
Thank you for the update.
What comes to mind is using the different data events for the settings that you want to save. For example for the sorting - this would be the Sorted event. You can also handle the Grouped and Filtered events. You can execute the saving inside the different events to make sure that the settings that you want to preserve are still available.
Alternatively, if you are manually unloading the control in code, you can execute the saving before that.
Hope you find this helpful.
Regards,
Vladimir Stoyanov
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/.