Hello all,
We are going to be using Essential Grid for a number of displays in a windows forms application. Part of the requirement is that the user be able to configure and save individual grid layouts (hidden columns, column order, column width, and column name). I was hoping that there was a method to save the style info and reload it, between application runs.
After looking through the docs, it appears that I will need to serialize the styleinfo class, save it to a file and reload. Am I on the right track here? cane anyone suggest a better method?
Thanks,
Doug
Panther Systems
AD
Administrator
Syncfusion Team
August 29, 2003 12:56 PM UTC
If this is a GridControl, then you can use GridModel.LoadBinary and GridModel.SaveBinary (or LoadSoap & SaveSoap) to serialize your grids.
If these are GridDataBoundGrids, then we currently don't support direct serialization og this grid. We will at some point. Right now, you would have to do things yourself. Here is a forum tread that has a sample that serializes out column order and size. http://www.syncfusion.com/forums/message.asp?MessageID=3918
DL
Doug Lind
August 29, 2003 01:23 PM UTC
Thanks Clay,
This looks like a goood approach for me.
Doug
> If this is a GridControl, then you can use GridModel.LoadBinary and GridModel.SaveBinary (or LoadSoap & SaveSoap) to serialize your grids.
>
> If these are GridDataBoundGrids, then we currently don't support direct serialization og this grid. We will at some point. Right now, you would have to do things yourself. Here is a forum tread that has a sample that serializes out column order and size. http://www.syncfusion.com/forums/message.asp?MessageID=3918
SU
Santosh U
July 17, 2009 02:57 PM UTC
Hi,
The above given links seems to be not working. Can you please update me with the new link. This will be very useful feature.
Thanks
SU
Santosh U
July 24, 2009 03:29 PM UTC
Hi Rajdurai,
I am sorry, I had tried to download the project link which was given but the zip file seems to be not available now. I get 404 error.
Would it be possible to provide some project (C#).
Thanks,
Satosh U.
PT
Peter Trevor
July 24, 2009 05:40 PM UTC
Hi. I'm not a Syncfusion expert but if it's a GridGroupingControl that you want to persist the style of I use the following code:
private void SetGridProperties(GridGroupingControl thisGrid, string thisID)
{
try
{
XmlReader xr1 = new XmlTextReader(thisID + "Schema.xml");
XmlReader xr2 = new XmlTextReader(thisID + "LooknFeel.xml");
thisGrid.ApplyXmlSchema(xr1);
thisGrid.ApplyXmlLookAndFeel(xr2);
xr1.Close();
xr2.Close();
}
catch
{
thisGrid.TableModel.ColWidths.ResizeToFit(GridRangeInfo.Row(0), GridResizeToFitOptions.None);
for (int i = 1; i <= thisGrid.TableModel.RowCount; i++)
thisGrid.TableModel.ColWidths.ResizeToFit(GridRangeInfo.Row(i), GridResizeToFitOptions.NoShrinkSize);
}
}
private void SaveGridProperties(GridGroupingControl thisGrid, string thisID)
{
try
{
XmlTextWriter xw1 = new XmlTextWriter(thisID + "GridSchema.xml", Encoding.UTF8);
XmlTextWriter xw2 = new XmlTextWriter(thisID + "GridLooknFeel.xml", Encoding.UTF8);
xw1.Formatting = Formatting.Indented;
xw2.Formatting = Formatting.Indented;
thisGrid.WriteXmlSchema(xw1);
thisGrid.WriteXmlLookAndFeel(xw2);
xw1.Close();
xw2.Close();
}
catch
{
}
}
SU
Santosh U
August 13, 2009 03:14 PM UTC
Hi Rajadurai,
I have tried this and its working fine. I changed to use for GGC but it give me some weired output. I have copied the code which i have changed below.
try
{
//serialize out the row heights & columnwidths
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MySizes.bin", FileMode.Create, FileAccess.Write, FileShare.None);
//handle the mappingnames
//GridBoundColumnsCollection col = (GridBoundColumnsCollection)this.gridDataBoundGrid1.GridBoundColumns;
GridColumnDescriptorCollection col = (GridColumnDescriptorCollection)gridGroupingControl1.TableDescriptor.Columns;
//gridGroupingControl1.
//if (col.Count == 0)
// col = this.gridDataBoundGrid1.Binder.InternalColumns;
int nCols = col.Count;
string[] a = new string[nCols];
int i = 0;
foreach (GridColumnDescriptor c in col)
a[i++] = c.MappingName;
formatter.Serialize(stream, a);
formatter.Serialize(stream, gridGroupingControl1.TableControl.Model.ColWidths.Dictionary);
//formatter.Serialize(stream, this.gridDataBoundGrid1.Model.ColWidths.Dictionary);
stream.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
I have just commented one if statement. I am not sure if that is creating problem. Please help me.
Thanks,
Santosh
SU
Santosh U
September 5, 2009 06:38 AM UTC
Hi All,
I could achieve this by using Pedro' example,
Thanks Pedro.
Regards,
Santosh U