Columns are gone if reordering upon reload.

4 posts, 0 answers
  1. Johannes
    Johannes avatar
    16 posts
    Member since:
    Nov 2012

    Posted 11 Jun 2013 Link to this post

    Hi,

    I've been experimenting a little with the PersistenceFramework over the course of the day and I've found some, according to me,
    mystic behaviour.

    When the window containing my RadGridView closes I run this code:
    var manager = new PersistenceManager();
    var stream = manager.Save(dgOrderOverview);
     
    using (var fileStream = File.Create(System.AppDomain.CurrentDomain.BaseDirectory + "\\objstore.hf"))
    {
        stream.CopyTo(fileStream);
    }

    and when I open it up again the following code is run:
    //Check if any persistence file exists, and if so, load the view
    if (File.Exists(System.AppDomain.CurrentDomain.BaseDirectory + "\\objstore.hf"))
    {
        var manager = new PersistenceManager();
     
        try
        {
            var fileStream = File.OpenRead(System.AppDomain.CurrentDomain.BaseDirectory + "\\objstore.hf");
            manager.Load(dgOrderOverview, fileStream);
            fileStream.Close();
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.Message, "MYAPPNAME");
        }
    }
     
    //Load Context Menu
    RadContextMenu ctxMenu = new RadContextMenu();
    RadMenuItem item = new RadMenuItem();
     
    foreach (Telerik.Windows.Controls.GridViewColumn column in dgOrderOverview.Columns)
    {
        RadMenuItem sitem = new RadMenuItem() { Header = column.Header, IsCheckable = true, IsChecked = true };
        sitem.SetBinding(RadMenuItem.IsCheckedProperty, new Binding("IsVisible") { Mode = BindingMode.TwoWay, Source = column });
        ctxMenu.Items.Add(sitem);
    }
     
    RadContextMenu.SetContextMenu(dgOrderOverview, ctxMenu);

    For the sake of things it should be noted that I have a RadContextMenu loading in order to be able to show/hide columns in the RadGridView.

    Now, here's to the tricky bit, I have a RadContextMenu where the user can set the visibility of the columns, and IF the user ONLY uses this, everything is fine and dandy, visibility properties as set as they should upon reload. However IF the user decides to rearrange the columns, the next time he/she opens up the window, ALL columns are gone, there's NOTHING there at all.

    So in short:
    * Show / Hide columns using the RadContextMenu bound to the RadGridView works fine, persistence is kept and loads nicely.
    * Rearrange columns and the persistence is broken and no columns as viewable upon opening the window.

    As a little twist, the columns are all visible in the ContextMenu and their visibility are set as they should, but the GridView doesn't display them.

    A little help, please?

    P.S
    I run the following version of the Telerik components:
    RadControls_for_WPF_2013_1_0527_DEV_hotfix
    D.S
  2. Johannes
    Johannes avatar
    16 posts
    Member since:
    Nov 2012

    Posted 12 Jun 2013 Link to this post

    Update on this issue, I read some other post about the ServiceProvider and adding a new "ICustomPropertyProvider". This worked well for the column sorting, it now works. However, that meant that the visibility state of the columns went all tits up and all columns are set as visible upon reloading the window.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 13 Jun 2013 Link to this post

    Hi Johannes,
    In order to save the visibility of the GridView columns you should just add an IsVisible property to the ColumnSetting and set it on save(the ProvideValue method) and take its value on load(the RestoreValue methiod).
    I've attached a sample project which shows this so could you please examine it and if you have further questions don't hesitate to ask.

    Regards,
    Zarko
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Johannes
    Johannes avatar
    16 posts
    Member since:
    Nov 2012

    Posted 14 Jun 2013 Link to this post

    Hi Zarko,

    thanks for clarifying and thanks for the code sample. It works like charm now.

    Thanks for all help! :) :)
Back to Top