Articles in this section
Category / Section

How to Print the data of the OlapGrid Control

1 min read

We can able to print the data of the OlapGrid Control by using PrintPreviewControl. Please refer the below steps to achieve the same.

  1. Add the OlapGridPrintDocument Class which is used to provide the internal grid of OlapGrid for Printing.

C#

 

 
class OlapGridPrintDocument: IPrintDocument
    {
        private OlapGrid olapGrid;
        private IGridPrintPaginator gridPaginator;
        
        /// <summary>
        /// A constructor that initializes the print pages with olap grid view.
        /// </summary>
        /// <param name="grid">OlapGridControl</param>
        public OlapGridPrintDocument(OlapGrid grid)
        {
            this.olapGrid = grid;
            gridPaginator = this.olapGrid.InternalGrid.Model.ActiveGridView as IGridPrintPaginator;
        }
 
        #region IPrintDocument members
        /// <summary>
        /// A method that returns print visual of the respective page.
        /// </summary>
        /// <param name="pageNo">page number</param>
        /// <returns>FrameworkElement</returns>
        public FrameworkElement GetPage(int pageNo)
        {
            FrameworkElement element = gridPaginator.GetPrintVisualAt(pageNo, this.PageSize);
            return element;
        }
 
        /// <summary>
        /// Gets or sets the thickness of outer border of framework element.
        /// </summary>
        public Thickness Margin
        {
            get;
            set;
        }
 
        /// <summary>
        /// A method that sets the size of print page and count of total pages.
        /// </summary>
        public void OnSetPageSize()
        {
            this.gridPaginator.SetPrintPageSize(this.PrintablePageSize);
            this.TotalPages = this.gridPaginator.GetPrintTotalPageCount(this.PrintablePageSize);
        }
 
        /// <summary>
        /// Gets or sets the size of the print page.
        /// </summary>
        public Size PageSize
        {
            get;
            set;
        }
 
        /// <summary>
        /// Gets or sets the client size of the print page.
        /// </summary>
        public Size PrintablePageSize
        {
            get;
            set;
        }
 
        /// <summary>
        /// Gets or sets the total pages to print.
        /// </summary>
        public int TotalPages
        {
            get;
            set;
        }
        #endregion
    }

 

  1. Create a button for Printing option and the below for Printing the OlapGrid data.

C#

 
public MainWindow()
        {
            ViewModel.ViewModel.ConnectionString = this.GetConnectionString();
            InitializeComponent();
        }
        public void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            Window printWindow = new Window();
            olapGrid1.InternalGrid.PrintRange = GridRangeInfo.Table();
            OlapGridPrintDocument printDocument = new OlapGridPrintDocument(olapGrid1);
            printDocument.Margin = new Thickness(20);
            PrintPreviewControl navigationControl = new PrintPreviewControl(printDocument);
            navigationControl.HeaderTemplate = null;
            navigationControl.FooterTemplate = null;
            printWindow.Title = "Print Preview";
            printWindow.Content = navigationControl;
            printWindow.ShowDialog();
        }

 

 

Figure: Print Preview window for OlapGrid

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied