Serialization and Deserialization in Windows Forms Pivot Grid

28 Apr 202119 minutes to read

Serialization and deserialization support allows to serialize and deserialize the settings of pivot grid control.

Serializing pivot grid

Serialization is a process that allows to save the settings of pivot grid control by exporting its current settings to an XML file. It can be achieved with the help of any of the following methods.

Serializing using save file dialog

Pivot grid control allows to save its settings to the desired location in *.xml format by using the Serialize() method.

Refer to the below code sample to serialize the pivot grid control using save file dialog.

this.pivotGridControl1.Serialize();
Me.pivotGridControl1.Serialize()

The below screenshot illustrates the serialized content of pivot grid control.

Serialized_PivotGrid

Serializing using stream

Pivot grid control allows to save its settings with the help of Serialize(Stream) method by passing the stream as parameter.

Refer to the below code sample to serialize the pivot grid control as stream.

using (FileStream fileStream = File.Create("PivotGrid.xml"))
{
    this.pivotGridControl1.Serialize(fileStream);
}
Using fileStream As FileStream = File.Create("PivotGrid.xml")
    Me.pivotGridControl1.Serialize(fileStream)
End Using

Serializing using specific file

Pivot grid control allows to save its settings with the help of Serialize(String) method by passing the file path as parameter.

Refer to the below code sample to serialize the pivot grid control as xml file.

this.pivotGridControl1.Serialize(@"D:\PivotGrid.xml");
Me.pivotGridControl1.Serialize("D:\PivotGrid.xml")

Serializing to XML string

Pivot grid control allows to save its settings into a XML string using the SerializeToXml() method.

Refer to the below code sample to serialize the pivot grid control as xml string.

string xmlString = this.pivotGridControl1.SerializeToXml();
Dim xmlString As String = Me.pivotGridControl1.SerializeToXml()

Customizing serialization using options

The serialization of pivot grid control can be customized by using the instance of SerializationOptions. The instance of serialization options needs to be passed as an argument of Serialize(String,SerializationOptions) or Serialize(Stream,SerializationOptions) method based on the requirement.

Serializing grouping bar items

By default, the pivot grid control allows to serialize the items of grouping bar. The serialization of grouping bar items can be disabled by setting the SerializeGrouping property to false.

using (var file = File.Create("PivotGrid.xml"))
{
    SerializationOptions options = new SerializationOptions();
    options.SerializeGrouping = false;
    this.pivotGridControl1.Serialize(file, options);
}
Using file = File.Create("PivotGrid.xml")
    Dim options As New SerializationOptions()
    options.SerializeGrouping = False
    Me.pivotGridControl1.Serialize(file, options)
End Using

Serializing sorted items

By default, the pivot grid control allows to serialize the sorted items. The serialization of sorted items can be disabled by setting the SerializeSorting property to false.

using (FileStream fileStream = File.Create("PivotGrid.xml"))
{
    SerializationOptions options = new SerializationOptions();
    options.SerializeSorting = false;
    this.pivotGridControl1.Serialize(fileStream, options);
}
Using fileStream As FileStream = File.Create("PivotGrid.xml")
    Dim options As New SerializationOptions()
    options.SerializeSorting = False
    Me.pivotGridControl1.Serialize(fileStream, options)
End Using

Serializing filtered items

By default, the pivot grid control allows to serialize the filtered items. The serialization of filtered items can be disabled by setting the SerializeFiltering property to false.

using (var file = File.Create("PivotGrid.xml"))
{
    SerializationOptions options = new SerializationOptions();
    options.SerializeFiltering = false;
    this.pivotGridControl1.Serialize(file, options);
}
Using file = File.Create("PivotGrid.xml")
    Dim options As New SerializationOptions()
    options.SerializeFiltering = False
    Me.pivotGridControl1.Serialize(file, options)
End Using

Serializing pivot row items

By default, the pivot grid control allows to serialize the collection of pivot row items. The serialization of pivot row items can be disabled by setting the SerializePivotRows property to false.

using (var file = File.Create("PivotGrid.xml"))
{
    SerializationOptions options = new SerializationOptions();
    options.SerializePivotRows = false;
    this.pivotGridControl1.Serialize(file, options);
}
Using file = File.Create("PivotGrid.xml")
    Dim options As New SerializationOptions()
    options.SerializePivotRows = False
    Me.pivotGridControl1.Serialize(file, options)
End Using

Serializing pivot column items

By default, the pivot grid control allows to serialize the collection of pivot column items. The serialization of pivot column items can be disabled by setting the SerializePivotColumns property to false.

using (var file = File.Create("PivotGrid.xml"))
{
    SerializationOptions options = new SerializationOptions();
    options.SerializePivotColumns = false;
    this.pivotGridControl1.Serialize(file, options);
}
Using file = File.Create("PivotGrid.xml")
    Dim options As New SerializationOptions()
    options.SerializePivotColumns = False
    Me.pivotGridControl1.Serialize(file, options)
End Using

Serializing pivot calculation items

By default, the pivot grid control allows to serialize the collection of pivot column items. The serialization of pivot column items can be disabled by setting the SerializePivotCalculations property to false.

using (var file = File.Create("PivotGrid.xml"))
{
    SerializationOptions options = new SerializationOptions();
    options.SerializePivotCalculations = false;
    this.pivotGridControl1.Serialize(file, options);
}
Using file = File.Create("PivotGrid.xml")
    Dim options As New SerializationOptions()
    options.SerializePivotCalculations = False
    Me.pivotGridControl1.Serialize(file, options)
End Using

Serializing conditional formats

By default, the pivot grid control allows to serialize the conditional formats applied to it. The serialization of conditional formats can be disabled by setting the SerializeConditionalFormats property to false.

using (var file = File.Create("PivotGrid.xml"))
{
    SerializationOptions options = new SerializationOptions();
    options.SerializeConditionalFormats = false;
    this.pivotGridControl1.Serialize(file, options);
}
Using file = File.Create("PivotGrid.xml")
    Dim options As New SerializationOptions()
    options.SerializeConditionalFormats = False
    Me.pivotGridControl1.Serialize(file, options)
End Using

Serializing expand and collapse state

By default, the pivot grid control allows to serialize the expand and collapse state of expanders in row and column headers. The serialization of expand and collapse state of expanders can be disabled by setting the SerializeExpandCollapseState property to false.

using (var file = File.Create("PivotGrid.xml"))
{
    SerializationOptions options = new SerializationOptions();
    options.SerializeExpandCollapseState = false;
    this.pivotGridControl1.Serialize(file, options);
}
Using file = File.Create("PivotGrid.xml")
    Dim options As New SerializationOptions()
    options.SerializeExpandCollapseState = False
    Me.pivotGridControl1.Serialize(file, options)
End Using

Deserializing pivot grid

Deserialization is a process that allows to reconstruct the pivot grid control based on the settings stored in the XML file. It can be done with the help of any of the following methods.

Deserializing using open file dialog

The settings of pivot grid control can be deserialized with the help of Deserialize() method.

Refer to the below code sample to deserialize the pivot grid control using open file dialog.

this.pivotGridControl1.Deserialize();
Me.pivotGridControl1.Deserialize()

Deserializing using stream

The settings of pivot grid control can be deserialized with the help of Deserialize(Stream) method.

Refer to the below code sample to deserialize the pivot grid from stream.

using (FileStream fileStream = File.OpenRead("PivotGrid.xml"))
{
    this.pivotGridControl1.Deserialize(fileStream);
}
Using fileStream As FileStream = File.OpenRead("PivotGrid.xml")
    Me.pivotGridControl1.Deserialize(fileStream)
End Using

Deserializing using specific file

The settings of pivot grid control can be deserialized with the help of Deserialize(String) method by passing the path of the file as parameter.

Refer to the below code sample to deserialize the pivot grid from xml file.

this.pivotGridControl1.Deserialize(@"D:\PivotGrid.xml");
Me.pivotGridControl1.Deserialize("D:\PivotGrid.xml")

Deserializing from XML string

Pivot grid control allows to load its settings from the XML string using the DeserializeFromXml() method.

Refer to the below code sample to deserialize the pivot grid from xml string.

this.pivotGridControl1.DeserializeFromXml(xmlString);
Me.pivotGridControl1.DeserializeFromXml(xmlString)

Customizing deserialization using options

The deserialization of pivot grid control can be customized by using the instance of DeserializationOptions. The instance of deserialization options needs to be passed as an argument of Deserialize(String,DeserializationOptions) or Deserialize(Stream,DeserializationOptions) method based on the requirement.

Deserializing grouping bar items

By default, the pivot grid control allows to deserialize the items of grouping bar. The deserialization of grouping bar items can be disabled by setting the DeserializeGrouping property to false.

using (FileStream fileStream = File.OpenRead("PivotGrid.xml"))
{
    DeserializationOptions options = new DeserializationOptions();
    options.DeserializeGrouping = false;
    this.pivotGridControl1.Deserialize(fileStream, options);
}
Using fileStream As FileStream = File.OpenRead("PivotGrid.xml")
    Dim options As New DeserializationOptions()
    options.DeserializeGrouping = False
    Me.pivotGridControl1.Deserialize(fileStream, options)
End Using

Deserializing sorted items

By default, the pivot grid control allows to deserialize the sorting operation. The deserialization of sorted items can be disabled by setting the DeserializeSorting property to false.

using (FileStream fileStream = File.OpenRead("PivotGrid.xml"))
{
    DeserializationOptions options = new DeserializationOptions();
    options.DeserializeSorting = false;
    this.pivotGridControl1.Deserialize(fileStream, options);
}
Using fileStream As FileStream = File.Create("PivotGrid.xml")
    Dim options As New DeserializationOptions()
    options.DeserializeSorting = False
    Me.pivotGridControl1.Deserialize(fileStream, options)
End Using

Deserializing filtered items

By default, the pivot grid control allows to deserialize the filtering operation. The deserialization of filtered items can be disabled by setting the DeserializeFiltering property to false.

using (FileStream fileStream = File.OpenRead("PivotGrid.xml"))
{
    DeserializationOptions options = new DeserializationOptions();
    options.DeserializeFiltering = false;
    this.pivotGridControl1.Deserialize(fileStream, options);
}
Using fileStream As FileStream = File.OpenRead("PivotGrid.xml")
    Dim options As New DeserializationOptions()
    options.DeserializeFiltering = False
    Me.pivotGridControl1.Deserialize(fileStream, options)
End Using

Deserializing pivot row items

By default, the pivot grid control allows to deserialize the collection of pivot row items. The deserialization of pivot row items can be disabled by setting the DeserializePivotRows property to false.

using (FileStream fileStream = File.OpenRead("PivotGrid.xml"))
{
    DeserializationOptions options = new DeserializationOptions();
    options.DeserializePivotRows = false;
    this.pivotGridControl1.Deserialize(fileStream, options);
}
Using fileStream As FileStream = File.OpenRead("PivotGrid.xml")
    Dim options As New DeserializationOptions()
    options.DeserializePivotRows = False
    Me.pivotGridControl1.Deserialize(fileStream, options)
End Using

Deserializing pivot column items

By default, the pivot grid control allows to deserialize the collection of pivot column items. The deserialization of pivot column items can be disabled by setting the DeserializePivotColumns property to false.

using (FileStream fileStream = File.OpenRead("PivotGrid.xml"))
{
    DeserializationOptions options = new DeserializationOptions();
    options.DeserializePivotColumns = false;
    this.pivotGridControl1.Deserialize(fileStream, options);
}
Using fileStream As FileStream = File.OpenRead("PivotGrid.xml")
    Dim options As New DeserializationOptions()
    options.DeserializePivotColumns = False
    Me.pivotGridControl1.Deserialize(fileStream, options)
End Using

Deserializing pivot calculation items

By default, the pivot grid control allows to deserialize the collection of pivot calculation items. The deserialization of pivot calculation items can be disabled by setting the DeserializePivotCalculations property to false.

using (FileStream fileStream = File.OpenRead("PivotGrid.xml"))
{
    DeserializationOptions options = new DeserializationOptions();
    options.DeserializePivotCalculations = false;
    this.pivotGridControl1.Deserialize(fileStream, options);
}
Using fileStream As FileStream = File.OpenRead("PivotGrid.xml")
    Dim options As New DeserializationOptions()
    options.DeserializePivotCalculations = False
    Me.pivotGridControl1.Deserialize(fileStream, options)
End Using

Deserializing conditional formats

By default, the pivot grid control allows to deserialize the conditional formats applied to the it. The deserialization of conditional formats can be disabled by setting the DeserializeConditionalFormats property to false.

using (FileStream fileStream = File.OpenRead("PivotGrid.xml"))
{
    DeserializationOptions options = new DeserializationOptions();
    options.DeserializeConditionalFormats = false;
    this.pivotGridControl1.Deserialize(fileStream, options);
}
Using fileStream As FileStream = File.OpenRead("PivotGrid.xml")
    Dim options As New DeserializationOptions()
    options.DeserializeConditionalFormats = False
    Me.pivotGridControl1.Deserialize(fileStream, options)
End Using

Deserializing expand and collapse state

By default, the pivot grid control allows to deserialize the expand and collapse state of expanders in column and row headers. The deserialization of expand and collapse state of expanders can be disabled by setting the DeserializeExpandCollapseState property to false.

using (FileStream fileStream = File.OpenRead("PivotGrid.xml"))
{
    DeserializationOptions options = new DeserializationOptions();
    options.DeserializeExpandCollapseState = false;
    this.pivotGridControl1.Deserialize(fileStream, options);
}
Using fileStream As FileStream = File.OpenRead("PivotGrid.xml")
    Dim options As New DeserializationOptions()
    options.DeserializeExpandCollapseState = False
    Me.pivotGridControl1.Deserialize(fileStream, options)
End Using

A demo sample is available in the following location.

<Installed Drive>\Users\Public\Documents\Syncfusion\Windows\<Version Number>\PivotGrid.Windows\Samples\Serialization\Serialization Demo