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.
Unfortunately, activation email could not send to your email. Please try again.

For sticky columns

Thread ID:

Created:

Updated:

Platform:

Replies:

70525 Dec 14,2007 02:59 AM Dec 14,2007 06:05 AM Windows Forms 1
loading
Tags: GridControl
Kishor Nandode
Asked On December 14, 2007 02:59 AM

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


Golda Rebecal [Syncfusion]
Replied On December 14, 2007 06:05 AM

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



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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.

;