RadGridView Save/Load UserSettings + MVVM

16 posts, 0 answers
  1. Asela
    Asela avatar
    6 posts
    Member since:
    Jan 2011

    Posted 05 Jan 2011 Link to this post

    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

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 06 Jan 2011 Link to this post

    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
  3. Asela
    Asela avatar
    6 posts
    Member since:
    Jan 2011

    Posted 06 Jan 2011 Link to this post

    <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
  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 07 Jan 2011 Link to this post

    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
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 07 Jan 2011 Link to this post

    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
  6. Asela
    Asela avatar
    6 posts
    Member since:
    Jan 2011

    Posted 09 Jan 2011 Link to this post

    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

     

     

     

     

     

     

  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 10 Jan 2011 Link to this post

    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>>
  8. Asela
    Asela avatar
    6 posts
    Member since:
    Jan 2011

    Posted 13 Jan 2011 Link to this post

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

     

  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 13 Jan 2011 Link to this post

    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>>
  10. Stephan
    Stephan avatar
    14 posts
    Member since:
    Apr 2012

    Posted 27 Apr 2012 Link to this post

    The sample is no longer compilable using WPF GridView Q1/2012. Could you please fix and upload it again ?
  11. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 27 Apr 2012 Link to this post

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

  12. Joyce
    Joyce avatar
    2 posts
    Member since:
    Apr 2011

    Posted 30 Apr 2012 Link to this post

    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
  13. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 01 May 2012 Link to this post

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

  14. Joyce
    Joyce avatar
    2 posts
    Member since:
    Apr 2011

    Posted 01 May 2012 Link to this post

    Hi Maya,
    Got it thanks!
    Joyce
  15. parthiv
    parthiv avatar
    7 posts
    Member since:
    Sep 2017

    Posted 24 Nov in reply to Maya Link to this post

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

  16. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    61 posts

    Posted 28 Nov Link to this post

    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.
Back to Top