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

RadGridView Save/Load UserSettings + MVVM

22 Answers 1023 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Asela
Top achievements
Rank 1
Asela asked on 06 Jan 2011, 05:12 AM
Hi,

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

Sort by
0
Maya
Telerik team
answered on 06 Jan 2011, 01:34 PM
Hello Asela,

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 ?
  

Regards,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Asela
Top achievements
Rank 1
answered on 06 Jan 2011, 11:21 PM
<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
0
Maya
Telerik team
answered on 07 Jan 2011, 04:02 PM
Hi 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. 

Best wishes,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Maya
Telerik team
answered on 07 Jan 2011, 04:05 PM
Hi Asela,

You may find the sample project I mentioned attached in this post.
 

All the best,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Asela
Top achievements
Rank 1
answered on 10 Jan 2011, 12:54 AM

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

 

 

 

 

 

 

0
Maya
Telerik team
answered on 10 Jan 2011, 04:46 PM
Hi 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
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Asela
Top achievements
Rank 1
answered on 13 Jan 2011, 07:03 AM
Hi Maya,

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();

 

0
Maya
Telerik team
answered on 13 Jan 2011, 08:30 AM
Hi Asela,

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.
 

Greetings,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Stephan
Top achievements
Rank 1
answered on 27 Apr 2012, 10:21 AM
The sample is no longer compilable using WPF GridView Q1/2012. Could you please fix and upload it again ?
0
Vlad
Telerik team
answered on 27 Apr 2012, 11:48 AM
Hi,

 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 >>

0
Joyce
Top achievements
Rank 1
answered on 30 Apr 2012, 09:16 PM
Hi Vlad, 

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
0
Maya
Telerik team
answered on 01 May 2012, 07:27 AM
Hello Joyce,

You can find the example (RadPersistenceFramework/GridView Serialization) in your local installation of the demos. Do you still have troubles opening it ? 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Joyce
Top achievements
Rank 1
answered on 01 May 2012, 10:07 PM
Hi Maya,
Got it thanks!
Joyce
0
parthiv
Top achievements
Rank 1
answered on 24 Nov 2017, 07:22 AM

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...

0
Vladimir Stoyanov
Telerik team
answered on 28 Nov 2017, 02:14 PM
Hello Parthiv,

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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Marcus
Top achievements
Rank 1
answered on 05 May 2018, 10:06 AM

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

 

 

0
Marcus
Top achievements
Rank 1
answered on 07 May 2018, 09:21 AM

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

0
Vladimir Stoyanov
Telerik team
answered on 09 May 2018, 02:22 PM
Hello 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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 10 Mar 2021, 02:52 PM

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

0
Vladimir Stoyanov
Telerik team
answered on 15 Mar 2021, 11:48 AM

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/.

0
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 15 Mar 2021, 02:45 PM

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

0
Vladimir Stoyanov
Telerik team
answered on 18 Mar 2021, 10:12 AM

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/.

Tags
GridView
Asked by
Asela
Top achievements
Rank 1
Answers by
Maya
Telerik team
Asela
Top achievements
Rank 1
Stephan
Top achievements
Rank 1
Vlad
Telerik team
Joyce
Top achievements
Rank 1
parthiv
Top achievements
Rank 1
Vladimir Stoyanov
Telerik team
Marcus
Top achievements
Rank 1
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or