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

Is it possible to replicate a gridcontrol by painting it to graphics

Good day, I am working on an application that includes a panel with several types of controls placed on the panel. In order to paint the entire contents of the panel (all controls in the panel on one page) at a high quality resolution, each control is painted to graphics in a printDocument. MS Charts makes this easy with their print.printpaint() function, while other control types have to be painted from scratch. My question is, is there a fairly simple way for the syncfusion gridcontrol to be painted to graphics or does that have to be done from scratch?

Thanks.

7 Replies

AR Arulpriya Ramalingam Syncfusion Team October 5, 2017 01:41 PM UTC

Hi Travis, 
 
Thanks for using Syncfusion products. 
 
We could understand your scenario. In order to print the grid in a document with high quality, the PrintPage event of PrintDocument can be used. In that event, the grid can be drawn by using DrawGrid() method of GridControlBase. Please refer to the below code and sample, 
 
Code snippet 
 
PrintDocument doc = new PrintDocument(); 
PrintDialog printDialog = new PrintDialog(); 
if (printDialog.ShowDialog() == DialogResult.OK) 
{ 
    //Event Triggering 
    doc.PrintPage += Pd_PrintPage; 
    doc.Print(); 
} 
 
//Event Customization 
private void Pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) 
{ 
    //To draw the grid in print document 
    this.gridControl1.DrawGrid(e.Graphics); 
} 
 
 
Regards, 
Arulpriya 



TC Travis Chambers October 6, 2017 03:49 AM UTC

perfect! That is exactly what i needed. Somehow i missed the DrawGrid function when reading through the documentation. 

Thank you very much!

on a somewhat related note, is it possible to serialize a gridcontrol's properties but not its data so that i could load data into the grid and then load the serialized settings but keep the new data?


thanks.



AR Arulpriya Ramalingam Syncfusion Team October 9, 2017 04:44 PM UTC

Hi Travis, 
 
Thanks for your update. 
 
We have analyzed your scenario and the GridControl does have the below three types of serialization which serializes the grid style with cell value only. 
  • Binary
  • Xml
  • SOAP
 
We regret to let you know that GridControl does not have support to serialize the cell styles (look and feel) alone in above three kinds of serializations. So, we would suggest the GridGroupingControl for your requirements.  
 
The WriteXmlLookAndFeel() method of GridGroupingControl can be used to write the GridStyles alone into the xml file. Please refer to the below code, 
 
Code snippet 
XmlWriter xmlWriter = new XmlWriter("BaseLandF.xml"); 
this.gridGroupingControl1.WriteXmlLookAndFeel(xmlWriter); 
 
The ApplyXmlLookAndFeel() method of GridGroupingControl can be used to load the GridStyles from the xml file. Please refer to the below code, 
 
Code snippet 
XmlReader xmlReader = new XmlReader("BaseLandF.xml"); 
this.gridGroupingControl1.ApplyXmlLookAndFeel(xmlReader); 
 
 
Regards, 
Arulpriya 



TC Travis Chambers October 9, 2017 04:55 PM UTC

Thank you very much for that info. Before I attempt to recreate all of the grid controls I am using in my application (there are quite a few) to tye grouping control, let me ask you this: about how difficult and time consuming is it to recreate a grid control to a gridgroupingcontrol with the same visual styles, colors, etc.?



AR Arulpriya Ramalingam Syncfusion Team October 10, 2017 12:54 PM UTC

Hi Travis,  
  
Thanks for your update.  
  
We could understand your situation. The style customization of GridGroupingControl is as easy as the GridControl.  The visual styles can be set for GridGroupingControl is same as GridControl and also the cell styles can be customized by using QueryCellStyleInfo event of GridGroupingControl. So, you can easily modify the visual styles and cell styles in GridGroupingControl. Some of the API names will be differed for GridControl and GridGroupingControl, so if you provide us with what are all the style customization you had with GridControl? It would be more helpful for us to assist you better.  
 
UG links:  
  
Please let us know if you have any other queries.  
  
Regards,  
Arulpriya 


TC Travis Chambers October 12, 2017 06:02 PM UTC

It seems as though the grid grouping control is a good but different than the Gridcontrol in terms of the code behind, and considering the large number of grids im dealing with i tbink i will just rethink my method of filling the data when the xml properties are loaded. 

I would recommend that Syncfusion consider making it possible to serialize the properties only (no data) of the gridcontrol in the future as it would make the control that much more dynamic.

Thank you for your help.



AR Arulpriya Ramalingam Syncfusion Team October 13, 2017 12:56 PM UTC

Hi Travis, 
 
Thanks for your update. 
 
The ColumnStyles, RowStyles and the BaseStyles(Standard,ColumnHeader,RowHeader styles) can be serialized and deserialized when the GridStyleInfo for a cell is set by using ColStyles or RowStyles or BaseStylesMap properties. The Serialize() method of XmlSerializer can be used to serialize the GridStyleInfo alone of a column/row/BaseStyels and the Deserialize() method of XmlSerializer can be used to deserialize the GridStyleInfo of the serialized styles. Please make use of the below code and sample, 
 
Code snippet 
 
//To Serialize the Style 
private void serializeBtn_Click(object sender, EventArgs e) 
{ 
    Stream s = File.Create("GridStyle"); 
    XmlWriter xmlWriter = new XmlTextWriter(s, Encoding.Default); 
    //To serialize the Columns 
    XmlSerializer xmlSerializer = new XmlSerializer(typeof(GridStyleInfo)); 
    xmlSerializer.Serialize(xmlWriter, this.gridControl1.Model.ColStyles[3]); 
     
    ////To serialize the base style 
    //XmlSerializer xmlSerializer = new XmlSerializer(typeof(GridBaseStyle)); 
    //xmlSerializer.Serialize(xmlWriter, this.gridControl1.Model.BaseStylesMap.Standard); 
    ////To serialize the rowstyle 
    //XmlSerializer xmlSerializer = new XmlSerializer(typeof(GridStyleInfo)); 
    //xmlSerializer.Serialize(xmlWriter, this.gridControl1.Model.RowStyles[5]); 
 
    s.Close(); 
} 
 
//To deserialize the style 
private void button2_Click(object sender, EventArgs e) 
{ 
    Stream s = File.OpenRead("GridStyle"); 
    XmlReader xmlReader = new XmlTextReader(s); 
    //To deserialize the column styles alone 
    XmlSerializer xmlSerializer = new XmlSerializer(typeof(GridStyleInfo)); 
    this.gridControl1.Model.ColStyles[3] = (GridStyleInfo)xmlSerializer.Deserialize(xmlReader); 
     
    ////To deserialize the basestyle 
    //XmlSerializer xmlSerializer = new XmlSerializer(typeof(GridBaseStyle)); 
    //this.gridControl1.Model.BaseStylesMap.Standard = (GridBaseStyle)xmlSerializer.Deserialize(xmlReader); 
    ////To deserialize the rowstyles alone 
    //XmlSerializer xmlSerializer = new XmlSerializer(typeof(GridStyleInfo)); 
    //this.gridControl1.Model.RowStyles[5] = (GridStyleInfo)xmlSerializer.Deserialize(xmlReader); 
    s.Close(); 
    this.gridControl1.Refresh(); 
} 
 
 
Regards, 
Arulpriya 


Loader.
Live Chat Icon For mobile
Up arrow icon