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. Image for the cookie policy date
close icon

For sticky columns

Hi,
I am using Syncfusion grid. We have requirement where user can drag & drop (move) columns and this information (the order of columns) should be save such that when next time when user visit the same grid then the order of columns should be the same which he had selected previously.
Please let me know if there is any optimized way to save the current column orders and load the grid with same order next time.

Thanks,
Kishor


1 Reply

GR Golda Rebecal Syncfusion Team December 14, 2007 11:05 AM UTC

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.htm

Kindly let me know if this helps you.

We appreciate your interest in Syncfusion products.

Best regards,
Golda



Loader.
Live Chat Icon For mobile
Up arrow icon