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

Columns are gone if reordering upon reload.

3 Answers 96 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Johannes
Top achievements
Rank 1
Johannes asked on 11 Jun 2013, 02:34 PM
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

3 Answers, 1 is accepted

Sort by
0
Johannes
Top achievements
Rank 1
answered on 12 Jun 2013, 06:57 AM
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.
0
Zarko
Telerik team
answered on 13 Jun 2013, 03:22 PM
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.

0
Johannes
Top achievements
Rank 1
answered on 14 Jun 2013, 09:14 AM
Hi Zarko,

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

Thanks for all help! :) :)
Tags
PersistenceFramework
Asked by
Johannes
Top achievements
Rank 1
Answers by
Johannes
Top achievements
Rank 1
Zarko
Telerik team
Share this question
or