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

PersistenceManager does not handle re-organized columns correctly

2 Answers 22 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anne Lyon
Top achievements
Rank 1
Anne Lyon asked on 01 Feb 2017, 10:48 AM

I have a problem with Storing and reloading column order in a gridView. If I re-order columns and the move a column inbetween the already re-ordered columns, then the saved layout is no longer correct.

I start with 2 RadGridViews each with columns set as shown in file STEP1:

I have a callback on each ColumnReordered on grid 1 where I use a PersistanceManager to store the column-layout to a byte[], then I use the PersistanceManager again to read the byte[] into grid 2. For every time I do this I first reset the columns I grid 2 by looping through the Columns selection and setting the DisplayIndex to the same order as the columns are defined in the XAML.
First, in grid 1 I move column "3" to between"1" and "2". The result in Grid 2 is as expected, see file STEP2

Then, in grid 1 I move column "5" to between "3" and "2" and get the expected result in Grid 2 when I load the layout from Grid 1 using the PersistenceManager. See file STEP3

Finally, in Grid 1 I move "X" to between "1" and "3". Grid 21 then shows 1 X 3 5 2 4 6 which is correct. But when I reset grid 2 and load the layout from grid 1 I get the results as in file STEP4

Notice here that 2 & 5 have swapped places in Grid 2. I assume this is because of the way the PersistanceManager reads and applies the layout and in what order the columns are assigned their DisplayIndex.

Can anybody explain what happens and how to get around it? We use version 2014.2, will it help to upgrade? I do not want to buy an upgrade unless I am sure this will work...

2 Answers, 1 is accepted

Sort by
0
Anne Lyon
Top achievements
Rank 1
answered on 01 Feb 2017, 11:03 AM
BTW: Here is my XAML:

 

<Grid x:Name="LayoutRoot"  >
 
    <StackPanel Orientation="Horizontal">
            <telerik:RadGridView
         x:Name="MasterGrid"
       ColumnReordered="MasterGrid_ColumnReordered"   
            >
            <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn Header="1" UniqueName="A"  >
                    </telerik:GridViewDataColumn>
            <telerik:GridViewDataColumn Header="2" UniqueName="B" >
                </telerik:GridViewDataColumn>
            <telerik:GridViewDataColumn Header="3" UniqueName="C"   >
                    </telerik:GridViewDataColumn>
            <telerik:GridViewDataColumn  Header="4" UniqueName="D"   >
                </telerik:GridViewDataColumn>
            <telerik:GridViewDataColumn Header="5" UniqueName="E"  >
            </telerik:GridViewDataColumn>
            <telerik:GridViewDataColumn Header="6" UniqueName="K"  >
                </telerik:GridViewDataColumn>
            <telerik:GridViewDataColumn Header="X" UniqueName="L"  >
            </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
 
        <telerik:RadGridView
         x:Name="ToGrid"
            >
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="1" UniqueName="A"  >
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="2" UniqueName="B" >
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="3" UniqueName="C"   >
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn  Header="4" UniqueName="D"   >
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="5" UniqueName="E"  >
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="6" UniqueName="K"  >
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="X" UniqueName="L"  >
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
 
    </StackPanel>
</Grid>

 

//Here is my eventhandler in the code behind:
 
private void MasterGrid_ColumnReordered(object sender, Telerik.Windows.Controls.GridViewColumnEventArgs e)
{
    PersistenceManager manager;
    byte[] layout;
 
    //read layout from the MasterGrid
    manager = new PersistenceManager();
    using (var stream = manager.Save(MasterGrid))
    {
        layout = HelpFunctions.ReadFully(stream);
    }
 
    // reset the To-grid to its original layout
    int i = 0;
    foreach (GridViewColumn col in ToGrid.Columns)
    {
        col.DisplayIndex = i;
        i++;
    }
 
    //now apply the masterGrid's lauout to the To-Grid
    manager = new PersistenceManager();
    using (var ms = new MemoryStream())
    {
        ms.Write(layout, 0, layout.Length);
        ms.Position = 0L;
        manager.Load(ToGrid, ms);
    }
 
}
0
Anne Lyon
Top achievements
Rank 1
answered on 01 Feb 2017, 11:04 AM
//BTW Here is my code behind evnet handler:

 

private void MasterGrid_ColumnReordered(object sender, Telerik.Windows.Controls.GridViewColumnEventArgs e)
{
    PersistenceManager manager;
    byte[] layout;
 
    //read layout from the MasterGrid
    manager = new PersistenceManager();
    using (var stream = manager.Save(MasterGrid))
    {
        layout = HelpFunctions.ReadFully(stream);
    }
 
    // reset the To-grid to its original layout
    int i = 0;
    foreach (GridViewColumn col in ToGrid.Columns)
    {
        col.DisplayIndex = i;
        i++;
    }
 
    //now apply the masterGrid's lauout to the To-Grid
    manager = new PersistenceManager();
    using (var ms = new MemoryStream())
    {
        ms.Write(layout, 0, layout.Length);
        ms.Position = 0L;
        manager.Load(ToGrid, ms);
    }
 
}
Tags
GridView
Asked by
Anne Lyon
Top achievements
Rank 1
Answers by
Anne Lyon
Top achievements
Rank 1
Share this question
or