Articles in this section
Category / Section

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

2 mins read

Serialization and Deserialization

To serialize or deserialize the GridConditionalFormatDescriptorCollection of grid to or from xml file in WinForms GridGrouping, 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

Conclusion

I hope you enjoyed learning about how to serialize and deserialize the conditional formats collection in WinForms GridGroupingControl.

You can refer to our WinForms GridGrouping Control’s feature tour page to know about its other groundbreaking feature representations. You can also explore our  WinForms GridGrouping Control documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms GridGrouping Control and otherWinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Serialization for conditional format in WinForms GridGrouping

Samples:

C#: Serialization of ConditionalFormats CS

VB: Serialization of ConditionalFormats VB

Reference link: https://help.syncfusion.com/windowsforms/gridgrouping/serialization

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied