Skip to main content

DataControlSerializationOptions Class

Contains options that specify how column specific settings are stored to and restored from a stream or file in XML format.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v24.1.Core.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public class DataControlSerializationOptions

Remarks

The DataControlSerializationOptions provides two options: DataControlSerializationOptions.AddNewColumns and DataControlSerializationOptions.RemoveOldColumns. The first option specifies whether the columns that currently exist in the grid, but do not exist in a layout when it is restored, should be retained. The second option specifies whether the columns that exist in a layout when it is restored but do not currently exist in the grid, should be discarded.

To save the grid layout, use the DataControlBase.SaveLayoutToStream or DataControlBase.SaveLayoutToXml method. To load the layout, use the DataControlBase.RestoreLayoutFromStream or DataControlBase.RestoreLayoutFromXml method.

To learn more, see Saving and Restoring Layout.

Note

To correctly save and restore the grid layout, grid columns should be uniquely identified, using the x:Name attribute.

Example

This example shows how to save the GridControl‘s layout to a memory stream. To do this, click the Save Layout button. Click the Restore Layout button to restore the saved layout.

Serialize the WPF Grid

View Example: Save Layout and Restore It from a Memory Stream

<dxg:GridControl x:Name="grid"
                 dx:DXSerializer.StoreLayoutMode="All" 
                 dxg:GridSerializationOptions.AddNewColumns="False" 
                 dxg:GridSerializationOptions.RemoveOldColumns="False"
                 UseFieldNameForSerialization="True">
    <dxg:GridColumn FieldName="IssueName"/>
    <dxg:GridColumn FieldName="IssueType"/>
    <dxg:GridColumn FieldName="IsPrivate" Header="Private"/>
    <dxg:GridControl.View>
        <dxg:TableView AutoWidth="True"/>
    </dxg:GridControl.View>
</dxg:GridControl>

<StackPanel Grid.Row="1" Orientation="Vertical">
    <StackPanel Orientation="Horizontal">
        <Button Margin="1" Content="Add a New Column" Click="OnAddNewColumn"/>
    </StackPanel>
    <StackPanel Orientation="Horizontal">
        <Button Content="Save Layout" Margin="1" Click="OnSaveLayout"/>
        <Button Content="Restore Layout" Margin="1" Click="OnRestoreLayout"/>
    </StackPanel>
</StackPanel>
public partial class Window1 : Window {
    MemoryStream layoutStream;
    public Window1() {
        InitializeComponent();
        grid.ItemsSource = IssueList.GetData();
    }

    void OnSaveLayout(object sender, RoutedEventArgs e) {
        layoutStream = new MemoryStream();
        grid.SaveLayoutToStream(layoutStream);
    }
    void OnRestoreLayout(object sender, RoutedEventArgs e) {
        layoutStream.Position = 0;
        grid.RestoreLayoutFromStream(layoutStream);
    }
    void OnAddNewColumn(object sender, RoutedEventArgs e) {
        grid.Columns.Add(new DevExpress.Xpf.Grid.GridColumn() { FieldName = "IsPrivate" });
    }
}

Inheritance

Object
DataControlSerializationOptions
See Also