Print Chartview and PivotGrid together

4 posts, 1 answers
  1. Thomas
    Thomas avatar
    6 posts
    Member since:
    Jan 2015

    Posted 07 Jun 2015 Link to this post

    Hello,

     is there a possibility to print the chartview and the Pivotgrid together in one 

    Printdocument? 

     

    regards

    Thomas

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 08 Jun 2015 Link to this post

    Hi Thomas,

    Thank you for writing. 

    This is possible and to achieve it you should create a custom class that implements IPrintable. For example:
    class MyPrinter : IPrintable
    {
        public IPrintable Chart { get; set; }
     
        public IPrintable Pivot { get; set; }
     
        private int pages;
     
        public int BeginPrint(RadPrintDocument sender, System.Drawing.Printing.PrintEventArgs args)
        {
            this.pages = Chart.BeginPrint(sender, args) + Pivot.BeginPrint(sender, args);
     
            return pages;
        }
     
        public bool EndPrint(RadPrintDocument sender, System.Drawing.Printing.PrintEventArgs args)
        {
            return false;
        }
     
        public bool PrintPage(int pageNumber, RadPrintDocument sender, System.Drawing.Printing.PrintPageEventArgs args)
        {
            if (pageNumber < pages)
            {
                this.Pivot.PrintPage(pageNumber, sender, args);
     
                return true;
            }
     
            this.Chart.PrintPage(1, sender, args);
            return false;
        }
     
        public Form GetSettingsDialog(RadPrintDocument document)
        {
            return null;
        }

    Then you can use the above class to create new PrintDocument:
    RadPrintDocument doc = new RadPrintDocument();
     
    doc.AssociatedObject = new MyPrinter()
    {
        Chart = chart1,
        Pivot = radPivotGrid1
    };
     
    RadPrintPreviewDialog dialog = new RadPrintPreviewDialog();
    dialog.Document = doc;
    dialog.ShowDialog();

    Please let me know if there is something else I can help you with.

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Thomas
    Thomas avatar
    6 posts
    Member since:
    Jan 2015

    Posted 08 Jun 2015 in reply to Dimitar Link to this post

    Hello Dimitar,

    thank you for your help. It was a fast and very helpful answer.
    Some modifications had to be done in order to have a good solution.

    1. Printersettings 
    2. First Chartprint then Pivotprint
    3. Pagenumber check (in case of landscape = false different number of pages)

        class MyPrinter : IPrintable
        {
            public IPrintable Chart { get; set; }
            public IPrintable Pivot { get; set; }
            private int pagesP;
            private int pagesC;
            private int pages;
            public int BeginPrint(RadPrintDocument sender, System.Drawing.Printing.PrintEventArgs args)
            {
                this.pagesC = Chart.BeginPrint(sender, args);
                this.pagesP = Pivot.BeginPrint(sender, args);
                this.pages = pagesC + pagesP;
                return pages;
            }
            public bool EndPrint(RadPrintDocument sender, System.Drawing.Printing.PrintEventArgs args)
            {
                return false;
            }
            public bool PrintPage(int pageNumber, RadPrintDocument sender, System.Drawing.Printing.PrintPageEventArgs args)
            {
                if (pageNumber <= pagesC)
                {
                    this.Chart.PrintPage(pageNumber, sender, args);
                    return pageNumber < pages;
                }
                this.Pivot.PrintPage(pageNumber-pagesC, sender, args);
                return pageNumber < pages;
            }
            public Form GetSettingsDialog(RadPrintDocument document)
            {
                return  Pivot.GetSettingsDialog(document);
           }
        }

    best regards

    Thomas

     

  5. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 09 Jun 2015 Link to this post

    Hello Thomas,

    Thank you for sharing your solution with the community. Do not hesitate to contact us if you have other questions.
     
    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top