)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to serialize and deserialize the conditional formats collection in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: January 6, 2017 |
Last Revised Date: December 24, 2019

Serialization and Deserialization

To serialize or deserialize the GridConditionalFormatDescriptorCollection of grid to or from xml file, the XMLSerializer can be used. XMLSerializer can be defined by GridConditionalFormatDescriptorCollection class which is having the ConditionalFormat collection of grids.

Serialization

C#

//To serialize the GridConditionalFormatDescriptor to  XML file
GridConditionalFormatDescriptorCollection collection = this.gridGroupingControl1.TableDescriptor.ConditionalFormats;
XmlSerializer xmlSerializer = new XmlSerializer(typeof(GridConditionalFormatDescriptorCollection));
XmlWriter writer = XmlWriter.Create("ConditionalSchema.xml");
 
//Serialize the specified ConditionalFormat write the XML document.
xmlSerializer.Serialize(writer, collection);
 
//Clear the ConditionalFormat of GridGroupingControl to see the difference.
this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Clear();
writer.Close();

 

VB

'To serialize the GridConditionalFormatDescriptor to  XML file
Dim collection As GridConditionalFormatDescriptorCollection = Me.gridGroupingControl1.TableDescriptor.ConditionalFormats
Dim xmlSerializer As New XmlSerializer(GetType(GridConditionalFormatDescriptorCollection))
Dim writer As XmlWriter = XmlWriter.Create("ConditionalSchema.xml")
 
'Serialize the specified ConditionalFormat write the XML document.
xmlSerializer.Serialize(writer, collection)
 
'Clear the ConditionalFormat of GridGroupingControl to see the difference.
Me.gridGroupingControl1.TableDescriptor.ConditionalFormats.Clear()
writer.Close()

 

Deserialization

C#

//DeSerialize the XML file to GridConditionalFormatDescriptorColloction
GridConditionalFormatDescriptorCollection collection;
FileDialog dlg = new OpenFileDialog();
dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
    XmlSerializer xmlSerializer = new XmlSerializer(typeof(GridConditionalFormatDescriptorCollection));
    XmlReader xr = new System.Xml.XmlTextReader(dlg.FileName);
    collection = (GridConditionalFormatDescriptorCollection)xmlSerializer.Deserialize(xr);
    //Apply the conditional formats.
    this.gridGroupingControl1.TableDescriptor.ConditionalFormats.InitializeFrom(collection);
    xr.Close();
}

 

VB

'DeSerialize the XML file to GridConditionalFormatDescriptorColloction
Dim collection As GridConditionalFormatDescriptorCollection
Dim dlg As FileDialog = New OpenFileDialog()
dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"
If dlg.ShowDialog() = DialogResult.OK Then
    Dim xmlSerializer As New XmlSerializer(GetType(GridConditionalFormatDescriptorCollection))
    Dim xr As XmlReader = New System.Xml.XmlTextReader(dlg.FileName)
    collection = CType(xmlSerializer.Deserialize(xr), GridConditionalFormatDescriptorCollection)
    'Apply the conditional formats.
    Me.gridGroupingControl1.TableDescriptor.ConditionalFormats.InitializeFrom(collection)
    xr.Close()
End If

 

Screenshot

Serialization for conditional format

Samples:

C#: Serialization of ConditionalFormats CS

VB: Serialization of ConditionalFormats VB

Reference link: https://help.syncfusion.com/windowsforms/classic/gridgroupingcontrol/serialization

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon