|
private void Serialization_Click(object sender, EventArgs e)
{
List<RecordExpandState> recordExpandState = new List<RecordExpandState>();
List<RecordSelectionState> recordSelectionState = new List<RecordSelectionState>();
foreach (Record record in this.gridGroupingControl1.Table.Records)
{
{
//To save the expanded records
recordExpandState.Add(new RecordExpandState() { recordIndex =this.gridGroupingControl1.Table.Records.IndexOf(record), IsExpanded = record.IsExpanded });
}
}
//To save the current record position
recordExpandState.Add(newRecordExpandState(this.gridGroupingControl1.Table.Records.IndexOf(this.gridGroupingControl1.Table.CurrentRecord)));
XmlTextWriter xmlWriter = new XmlTextWriter("RecordsExpandState.xml", Encoding.UTF8);
XmlSerializer serializer = new XmlSerializer(typeof(List<RecordExpandState>));
serializer.Serialize(xmlWriter, recordExpandState);
xmlWriter.Close();
XmlTextWriter xw1 = new XmlTextWriter("RecordSelectionState.xml", Encoding.UTF8);
}
private void Deserialization_Click(object sender, EventArgs e)
{
XmlReader xmlReader = new XmlTextReader("RecordsExpandState.xml");
XmlSerializer serializer = new XmlSerializer(typeof(List<RecordExpandState>));
List<RecordExpandState> expandState = serializer.Deserialize(xmlReader) as List<RecordExpandState>;
foreach (RecordExpandState recordExpandState in expandState)
{
//To retrieve the expanded records
this.gridGroupingControl1.Table.Records[recordExpandState.recordIndex].IsExpanded = recordExpandState.IsExpanded;
//To set the saved current record as current record after modifying the data source
this.gridGroupingControl1.Table.Records[recordExpandState.currentRecordIndex].SetCurrent();
}
} |