Trouble Printing Multi-Page DataGrid

sandygrdn's Avatar
Newbie Member
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 shabbir; 3Dec2010 at 15:04.. Reason: Code blocks
0
amtindia's Avatar, Join Date: Sep 2010
Newbie Member
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
0
amtindia's Avatar, Join Date: Sep 2010
Newbie Member
channel9.msdn.com/learn/courses/Silverlight4/SL4BusinessModule6/SL4LOB_06_02_MultipagePrinting