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

StyleSheet with GridDataBoundGrid

Hi,

I have some grid in my application. I want to apply the same "style" on each.

How I can do that ?

Best regard,

Martin

1 Reply

AD Administrator Syncfusion Team February 26, 2007 05:42 PM UTC

Hi Martin,

Share the style object:

Technique1:

If you want to serialize a style to disk and then load it from another grid, the serializable portion of the GridStyleInfo object is the Store member. You can serialize a style out and then load it back in. The gridControl.SaveXml() is used to save the (grid)GridModel object to the stream in XML format. The GridControl.InitializeFromXml() is used to recreate the GridControl with the data and property that was saved in the XML format.

// Save to xml file
grid1.SaveXml(@"c:\mygrid.xml");

// Load from file
grid2.InitializeFromXml(@"c:\mygrid.xml");

Technique2:

The SaveBinary method is used to save the current GridModel object to a file in binary format. The filename can be specified with FileName. The LoadBinary method is used to recreate a GridModel object from a file that holds data in binary format. Here is a code snippet.

//write out col2’s style

SaveBinary(@"C:\temp.sty", this.gridControl1.ColStyles[2]);

public void SaveBinary(string fileName, GridStyleInfo style)
{
Stream s = File.OpenWrite(fileName);
BinaryFormatter b = new BinaryFormatter();
b.Serialize(s, style.Store);
s.Close();
}

//set grid2’s col1 to use the saved style
this.gridControl2.ColStyles[1] = new GridStyleInfo(LoadBinary(@"C:\temp.sty"));


public GridStyleInfoStore LoadBinary(string fileName)
{
GridStyleInfoStore t = null;
Stream s = File.OpenRead(fileName);
try
{
BinaryFormatter b = new BinaryFormatter();
object obj = b.Deserialize(s);
t = obj as GridStyleInfoStore;
//t.fileName = fileName;
}
finally
{
s.Close();
}
return t;
}

Share the GridModel :

If you want two grid’s to share one grid model, then when you create the second grid, you pass the first grid’s model as an argument in the constructor.

this.gridControl2 = new GridControl( this.gridControl1.Model );

This will force to two grid’s to be exactly the same.

Share the GridTableStyle :

If you want the table style of one grid to be the same as the table style of another, you would just set them equal. But the tablestyle of an exisiting grid may have been cached to make drawing quicker, so you might need to call ResetVolatileData to force the grid to reload cached obejcts.

this.gridControl2.TableStyle = this.gridControl1.TableStyle;
this.gridControl2.ResetVolatileData();
this.gridControl2.Refresh();

Best Regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon