1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Trouble Printing Multi-Page DataGrid

Discussion in 'ASP' started by sandygrdn, Dec 3, 2010.

  1. sandygrdn

    sandygrdn New Member

    Joined:
    Sep 24, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Entrepreneur
    Location:
    Auckland, New Zealand
    I am having trouble printint a DataGrid across multiple pages. Here is the code I am using in the main page:

    Code:

    Code:
    PrintDocument doc = new PrintDocument(); 
                BackupPage page = new BackupPage(); 
                    List<object>allItems = myGrid.ItemsSource.OfType<object>().ToList(); 
                doc.Print("Backup Report"); 
                doc.PrintPage += (s, ea) => 
                    { 
                        int numberOfLinesAdded = 0; 
                        while (lineIndex < allItems.Count) 
                        { 
                            page.SetHeaderAndFooterText(account.Text, start.Text, end.Text); 
                            page.add_line(allItems[lineIndex]); 
                            page.Measure(new Size(ea.PrintableArea.Width, double.PositiveInfinity)); 
                            if (page.DesiredSize.Height > ea.PrintableArea.Height && numberOfLinesAdded > 0) 
                            { 
                                page.remove_line(allItems[lineIndex]); 
                                ea.HasMorePages = true; 
                                break; 
                            } 
                            lineIndex++; 
                            numberOfLinesAdded++; 
                        } 
     
                        ea.PageVisual = page; 
                    };
    
    And on BackupPage:

    Code:
    Code:
    public partial class BackupPage : UserControl 
        { 
            List<object> report = new List<object>(); 
     
            public BackupPage() 
            { 
                InitializeComponent(); 
                InvoiceDate.Text = DateTime.Today.ToShortDateString(); 
                myGrid2.ItemsSource = report; 
            } 
     
            public void SetHeaderAndFooterText(string account_name, string start_date, string end_date) 
            { 
                account.Text = account_name; 
                end.Text = end_date; 
                start.Text = start_date; 
            } 
     
            public void remove_line(object item) 
            { 
                report.Remove(item); 
            } 
     
            internal void add_line(object item) 
            { 
                report.Add(item); 
            } 
        }
    
    
    I am taking the rows from the main page "myGrid" and sending them to a BackupPage "myGrid2", but the rows don't show up. I have the myGrid2 set up exactly like myGrid. In the debugger I can see the count on report on BackupPage increment as well as the ItemsSource on myGrid2. So the rows are inserting into the page and the grid, they just aren't displaying on the printed page for some reason.

    I can't think of any reason that this isn't working. Any help would be greatly appreciated.
     
    Last edited by a moderator: Dec 3, 2010
  2. amtindia

    amtindia New Member

    Joined:
    Sep 24, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Director
    Location:
    Bangalore
    Home Page:
    Check out this video on Multiple Page Printing

    Hope it does helps.

    Advanced Millennium Technologies, a leading global services company, provides consulting, implementation, business transformation and operational solutions for clients across the globe. Feel free to hire a dedicated & skilled team of experts for developing your Custom Applications on Microsoft Silverlight platform.

    Warm Regards,
    Aby Varghese
    Director At AMT
     
  3. amtindia

    amtindia New Member

    Joined:
    Sep 24, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Director
    Location:
    Bangalore
    Home Page:
    channel9.msdn.com/learn/courses/Silverlight4/SL4BusinessModule6/SL4LOB_06_02_MultipagePrinting
     

Share This Page