Search code examples
c#winformslayoutdevexpresspivot-grid

Restoring layout in DevExpress PivotGridControl in my WinForms project does not work


I used following code to save and restore DevExpress PivotGridControl V7.2 layout:

//save layout
var fileName = string.Format(@"c:\pivot.xml");
pivotGridControl.SaveLayoutToXml(fileName);

//restore layout
var fileName = string.Format(@"c:\pivot.xml");
pivotGridControl.ForceInitialize();
pivotGridControl.RestoreLayoutFromXml(fileName);

But after running restore code, the layout doesn't change! Has my code any problem?


Solution

  • Thanks to Devexpress Support, following code, solved the problem:

    pivotGridControl.OptionsLayout.Columns.RemoveOldColumns = false;
    
    pivotGridControl.RetrieveFields();            
    foreach (PivotGridField field in pivotGridControl.Fields) {
        field.Name = "field" + field.FieldName;
    }