Hi Kishor,
You can achieve your requirement by storing the grid column orderinformation in a binary stream file while closing the form and loading that file after assigning the datasource for the GridDataBoundGrid.
Here is the code snippet:
// Storing the column order using Binary Serialization
try
{
//Serialize the row heights & column widths
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("..\\..\\ColumnOrder.egt", FileMode.Create, FileAccess.Write, FileShare.None);
//Handle the mappingnames
GridBoundColumnsCollection col = (GridBoundColumnsCollection)this.gridDataBoundGrid1.GridBoundColumns;
if (col.Count == 0)
col = this.gridDataBoundGrid1.Binder.InternalColumns;
int nCols = col.Count;
string[] a = new string[nCols];
int i = 0;
foreach (GridBoundColumn c in col)
a[i++] = c.MappingName;
formatter.Serialize(stream, a);
formatter.Serialize(stream, this.gridDataBoundGrid1.Model.ColWidths.Dictionary);
stream.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
//Loading Column Order
try
{
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("..\\..\\ColumnOrder.egt", FileMode.Open, FileAccess.Read, FileShare.None);
try
{
this.gridDataBoundGrid1.BeginUpdate();
//Handle the mappingnames
GridBoundColumnsCollection col = (GridBoundColumnsCollection)this.gridDataBoundGrid1.GridBoundColumns.Clone();
if (col.Count == 0)
col = this.gridDataBoundGrid1.Binder.InternalColumns;
//Deserialize GridBoundColumns
string[] a = (string[])formatter.Deserialize(stream);
this.gridDataBoundGrid1.GridBoundColumns.Clear();
foreach (string s in a)
{
GridBoundColumn c = col[s];
this.gridDataBoundGrid1.GridBoundColumns.Add(c);
}
this.gridDataBoundGrid1.Model.ColWidths.Dictionary =
(Syncfusion.Windows.Forms.Grid.GridRowColSizeDictionary)formatter.Deserialize(stream);
}
finally
{
this.gridDataBoundGrid1.EndUpdate();
this.gridDataBoundGrid1.Refresh();
stream.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Please refer to the attached sample that shows the same:
http://websamples.syncfusion.com/samples/Grid.Windows/F70525/main.htmKindly let me know if this helps you.
We appreciate your interest in Syncfusion products.
Best regards,
Golda