Reporting

Starting from version 2.7.0 grid functionality has been expanded with reporting and printing features. Programmers get simple and convenient interface for implementing new features and can significantly expand capabilities of target applications.

 

Print preview
 

 

 

Reporting features:

  • Software control of reporting with full customization support.
  • Possibility of adding any images or text to printed pages.
  • Page spanning: If there are too many fields to fit on one page, the fields
    can span two or more pages.
  • Repeating headers: to improve document readability the grid can insert
    headers to every printed page.
  • Reports for top-level headers and child headers with relevant content.
  • Hiding headers in reports
  • Repeating selectors: if content has many columns, the grid can span it over
    multiple pages. This feature can insert row selector to every page.
  • Print preview feature
  • Portrait or landscape page orientation

Grid provides standard printing and print preview features via PrintDocument object that enables document printing and previewing. The example below demonstrates implementation of document preview feature:


public void PrintPreview(Grid grid)
{
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = grid.PrintDocument;
ppd.ShowDialog(grid);
}

The following example demonstrates implementation of content printing feature.


public void PrintContent(Grid grid)
{
PrintDialog pd = new PrintDialog();
pd.Document = grid.PrintDocument;
pd.ShowDialog(grid);
}


The grid provides callback feature for print customization. This feature can also be used to customize page headers and footers:



grid.PrintPage += new System.EventHandler<PrintGridPageEventArgs>(OnPrintPage);

private void OnPrintPage(object sender, PrintGridPageEventArgs e)
{
//Print a page header
Rectangle rcHeader = new Rectangle(e.MarginBounds.X, e.PageBounds.Y, e.MarginBounds.Width, e.MarginBounds.Y - e.PageBounds.Y);
using(System.Drawing.StringFormat sf = new System.Drawing.StringFormat())
{
rcHeader.Inflate(0, -10);
sf.LineAlignment = StringAlignment.Far;
sf.Alignment = StringAlignment.Center;
e.Graphics.DrawString("This is a page header. Print your text here!", SystemFonts.MenuFont, SystemBrushes.GrayText, rcHeader, sf);
}

//Print a page footer
Rectangle rcFooter = new Rectangle(e.MarginBounds.X,
e.MarginBounds.Bottom,
e.MarginBounds.Width,
e.PageBounds.Bottom - e.MarginBounds.Bottom);
    using (System.Drawing.StringFormat sf = new System.Drawing.StringFormat())
{
rcFooter.Inflate(0, -10);
sf.LineAlignment = StringAlignment.Near;
sf.Alignment = StringAlignment.Center;
e.Graphics.DrawString(string.Format("Page {0} of {1}\r\nThis is a page footer. Print your text here!", e.PageNumber, e.PagesCount),
SystemFonts.MenuFont,
SystemBrushes.GrayText,
rcFooter,
sf);
}
}

Back to .Net Grid Features