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

Grid Styles and (sorta) templating

I''m working with an application that has are over a dozen distinct grids, which share several look and feel aspects - seemings to me this is a "poster case" for using base styles at design time. The issue of course is that the styles are still in flux and may well continue to be up uuntil the last moment. Changing any element of a style that has been replicated in in say 20 grids, means going back into the forms at design time and changing the style in 20 places. Have you any suggestions for ways to simplify dealing with evolving styles shared among many grids? Seems like templates won''t help because as I understand it, a template is intended to encapsulate an entire grid design, one can''t apply a template after the design of the grid is done and have it affect just the styles (Is this correct?) I''m wondering about subclassing GridControl - is it feasible populate the subclass with the base styles we want and then place that control on our forms - if a style needs to change, we touch up the common subclass and have it percolate onto into its subclass instances. But I''v run into some threads here that suggest there are problems - for example BeginInit() is mentioned... But maybe you folks have a better suggestion ? btw - we''re on ESuite V4, Studio 2003, c# ''best -Ralph

13 Replies

AD Administrator Syncfusion Team June 28, 2006 09:53 PM UTC

Hi Ralph , I am not clear about your question. Do you want to share the style among many grids? If so, please refer this. Share the serailized 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(); If I did not answer your question, please explain a little more about what you want, and I’ll try again. Best Regards, Haneef


RA ralph_lachance June 29, 2006 10:10 AM UTC

Haneef, Thanks for your reply. Let me give you some more details... Yes, I want to share a number a styles among a large number of grids, all on different forms and user controls. The grids are quite complex - lots of covered cells, lots of formatted column and row headers, holes within the data, readonly and "invisible" areas etc. Theses are decidedly not our father''s grids. (If necessary, I''ll send you a couple screen shots.) But deep down, there are only about a dozen distinct styles - and all ranges on all the grids share those common styles. The trick is that I want the styles to be in effect at design time so that we can see the final wysiwyg layout while the grid is being configured in the designer. More to the point, when I assign verious ranges on 20 different grids to a style (e.g. "column-heading-2") and a month from now, decide the some attribute of that style needs to change, I don''t want to have to touch every range - I don''t even want to touch the style in every one of the 20 grids that use that style - I just want to alter some common, shared object and then, if I open any of those grids ~at design time~, see the new settings in effect. The way I interpret the suggestions you offered is that they apply to changing styles at runtime. Is there a way to use any these techniques at design time. We''ve not had very good luck putting code in panel/form constructors and having that code take effect in the form designer. ''best -Ralph


RA ralph_lachance June 29, 2006 10:18 AM UTC

I should add - no two grids are alike... (despite their sharing common styles)


AD Administrator Syncfusion Team June 29, 2006 11:48 PM UTC

Hi Ralph, We are currently looking into this issue and will update you the details. Thanks for your patience. Best Regards, Haneef


AD Administrator Syncfusion Team July 3, 2006 03:18 PM UTC

Hi Raplh, Please accept my apologies for the delay in responding to this Issue. You should be able to derive a grid control and in the derived class add this method: /// /// Resets the property. /// public new void ResetBaseStylesMap() { BaseStylesMap.RegisterStandardStyles(); GridModel model = Model; /// Add your base styles below and then call .Modified = false //( you can also read from an xml file here and //deserialize styles from a file or resource here …) GridStyleInfo standard = model.BaseStylesMap["Standard"].StyleInfo; GridStyleInfo header = model.BaseStylesMap["Header"].StyleInfo; GridStyleInfo rowHeader = model.BaseStylesMap["Row Header"].StyleInfo; GridStyleInfo colHeader = model.BaseStylesMap["Column Header"].StyleInfo; GridFontInfo boldFont = new GridFontInfo(); boldFont.Bold = true; boldFont.Size = 8; boldFont.Facename = "Verdana"; standard.TextColor = Color.FromArgb(0, 21, 84); header.Interior = new BrushInfo(GradientStyle.Vertical, Color.FromArgb(51, 51, 102), Color.FromArgb(237, 240, 247)); rowHeader.Interior = new BrushInfo(GradientStyle.Horizontal, Color.FromArgb(51, 51, 102), Color.FromArgb(237, 240, 247)); standard.Font.Size = 9; standard.Font.Facename = "Tahoma"; standard.Interior = new BrushInfo(Color.FromArgb(237, 240, 247)); BaseStylesMap.Modified = false; Refresh(); } ///And also call this method from the derived grids ctor, e.g. public MyGridControl() { ResetBaseStylesMap(); } This makes sure the base style will only be serialized into code when explicitly change by the user for that grid. Here is a sample. http://www.syncfusion.com/Support/user/uploads/shareStyles_59853813.zip Let me know if this helps. Best Regards, Haneef


RA ralph_lachance July 4, 2006 10:07 AM UTC

Haneef Thank you for your reply. Your suggestion looks promising; We''ll try it out and reply. best... -Ralph


RA ralph_lachance July 4, 2006 04:35 PM UTC

Haneef, Almost but not quite... I am shipping you back a slightly modified version of your sample in which I make the following changes to the derived class. 1. Set the text color of base style "Standard" to RED 2. add a new base style to the derived class and set its Text Color to Red also. I then load the form into the designer and observe a) the text fields are all red. I then open the grid editor and set the Text property a range of 16 cells (4x4) to hello. Then I take a subset of that range (2x2) and set the base style of that range to my new base style. Then I close the grid designer and close the form. For reference: The "outer" 4x4 range is R4C3,R7C6 the inner 2x2 "subset" is R5C4,R6C5 Then I go back into the derived class and change the TextColor property of the ~new~ base style to a new color - Green, and RebuildAll I reopen the form designer and note that the inner 2x2 range of cells do NOT have TextColor green. Ditto if I run the project. The change I''ve made to the base style in the derived class is ignored. I did confirm the base style of that inner range is still set to the new base style, and that the TextColor of the new base style is indeed Green. I see that the form''s designer-generating code has overridden the base style - and I think I know why - but perhaps you folks can suggest a way to avoid it. Please note that this scenario is ~exactly~ what I want to support -- namely at design time assign ranges to new base styles that I define. And then, at a later time, adjust properties in those new base styles have have them take effect both at design and at run time. Sample attached.

ShareStyles1.zip


AD Administrator Syncfusion Team July 7, 2006 10:23 PM UTC

Hi Ralph, We are currently looking into this issue and will update you the details. Thanks for your patience. Best Regards, Haneef


AD Administrator Syncfusion Team July 11, 2006 05:52 PM UTC

Hi Ralph, My apologies for the delay in responding to this Issue. When you modify any base style in the designer mode then all the settings for the base styles will be serialized into the InitializeComponent code. The ctor settings have precedence over the InitializeComponent method. So InitializeComponent is executed after ctor settings. So even if you change TextColor in the ctor the InitializeComponent code will override it and apply the TextColor that was chosen in design-time. One idea would be to add another override in the derived grid class and then apply changes there that you do explicitly want to give precedence over changes made in InitializeComponent …, the Initialize() method could be a good place. But then you do of course lose the ability to change that color in the design-time. It’s either all or nothing. Thanks for your patience. Best Regards, Haneef


RA ralph_lachance July 16, 2006 12:01 PM UTC

Haneef, I feared this would be your answer. Seems to me this pokes holes in the both the concept of base styles and the much-touted styles approach to grid design. Surely I am not the only person who wants a) to have the same look and feel across multiple grids in an application b) have wysywg tools (design time) to design the shape and content of individual grids within a common set of base styles c) expect to use o-o techniquest to do all that (ie change a style in one place and expect the change to apply everywhere) Perhaps your architect would consider this for enhancement.... ''best -Ralph


AD Administrator Syncfusion Team July 18, 2006 09:05 AM UTC

Hi Ralph, I have contacted the development team regarding this and will let you the details, when I hear back from them. Thanks for your interest in Syncfusion Products. Regards, Haneef


AD Administrator Syncfusion Team July 19, 2006 05:09 AM UTC

 Here is the link for the sample 
Hi Ralph, I am not sure that the incident #26763 was also created by you, which has been update by Leo. updated in that incident. Regards, Haneef


AD Administrator Syncfusion Team July 19, 2006 05:13 AM UTC

Hi Ralph, Sorry for the inconvenience caused. I am not sure that the incident #26763 was also created by you, which has been update by Leo. Here is the link for the sample updated in that incident. Link : http://www.syncfusion.com/Support/user/uploads/sample_a727b30.zip Regards, Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon