This is a migrated thread and some comments may be shown as answers.

Printing many rows

1 Answer 43 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Zamel
Top achievements
Rank 1
Zamel asked on 01 Mar 2013, 10:19 AM
Hi!

I'm not sure if this is the right category since my problem involves two controls: GridView and RadRichTextBox.

I'm trying to print the gridview data and used radrichtextbox to do so. I followed your examples I found from searching, method is to manually create the document from header row to data rows and then finally add the cell values and then the document is to be passed back to the radrichtextbox which will handle the printing process. This part works fine, however, we have a requirement to display the printing date and page numbers as footers of the document. I can successfully include them also in the radrichtextbox document when printed. The only problem is the generation of page numbers. It always stays on page 1 but the page count is correct. I have my page footer formatted in this manner: Page {current page number} of {total pages} = Page 1 of 6.

This is the code I've used for creating the footer which I also found from your forums (really helpful):
private static Footer GetFooterElement()
        {
            var footer = new Footer();
            var footerBody = new RadDocument();
            var footerSection = new Telerik.Windows.Documents.Model.Section();
 
            var dateParagraph = new Telerik.Windows.Documents.Model.Paragraph();
            dateParagraph.TextAlignment = Telerik.Windows.Documents.Layout.RadTextAlignment.Left;
            dateParagraph.Inlines.Add(new Telerik.Windows.Documents.Model.Span(DateTime.UtcNow.ToString()));
 
            var pageNumberParagraph = new Telerik.Windows.Documents.Model.Paragraph();
            pageNumberParagraph.TextAlignment = Telerik.Windows.Documents.Layout.RadTextAlignment.Right;
 
            FieldRangeStart pageFieldStart = new FieldRangeStart() { Field = new PageField() { DisplayMode = FieldDisplayMode.Result } };
            FieldRangeEnd pageFieldEnd = new FieldRangeEnd() { Start = pageFieldStart };
            pageNumberParagraph.Inlines.Add(pageFieldStart);
            pageNumberParagraph.Inlines.Add(pageFieldEnd);
 
            FieldRangeStart numPagesFieldStart = new FieldRangeStart() { Field = new NumPagesField() { DisplayMode = FieldDisplayMode.Result } };
            FieldRangeEnd numPagesFieldEnd = new FieldRangeEnd() { Start = numPagesFieldStart };
            pageNumberParagraph.Inlines.Add(new Telerik.Windows.Documents.Model.Span(" of "));
            pageNumberParagraph.Inlines.Add(numPagesFieldStart);
            pageNumberParagraph.Inlines.Add(numPagesFieldEnd);
 
            var emptyParagraph = new Telerik.Windows.Documents.Model.Paragraph();
            footerSection.Blocks.Add(emptyParagraph);
 
            var table = new Table()
            {
                Borders = new TableBorders(new Telerik.Windows.Documents.Model.Border(BorderStyle.None)),
                PreferredWidth = new TableWidthUnit(TableWidthUnitType.Auto),
                LayoutMode = TableLayoutMode.AutoFit
            };
            var row = new TableRow();
            var cellA = new TableCell();
            var cellB = new TableCell();
 
            cellA.Blocks.Add(dateParagraph);
            cellB.Blocks.Add(pageNumberParagraph);
            cellB.Blocks.Add(new Telerik.Windows.Documents.Model.Paragraph());
            cellB.TextAlignment = Telerik.Windows.Documents.Layout.RadTextAlignment.Right;
 
            row.Cells.Add(cellA);
            row.Cells.Add(cellB);
            table.Rows.Add(row);
 
            footerSection.Blocks.Add(table);
 
            footerBody.Sections.Add(footerSection);
            footerBody.MeasureAndArrangeInDefaultSize();
            footerBody.CaretPosition.MoveToInline(cellA.EnumerateChildrenOfType<Telerik.Windows.Documents.
                Model.Inline>().Last().GetAssociatedLayoutBoxes().Last() as InlineLayoutBox, 0);
            footerBody.UpdateAllFields(FieldDisplayMode.Result);
 
            footer.Body = footerBody;
            return footer;
        }

Please help me to fix this. I cannot find any other way to fix this since the page numbers are being auto generated by your control.

Hoping for your immediate assistance.


Thanks,
Zamel

Additional info:
Our gridview columns are created dynamically. Do you think that has anything to do with it?

1 Answer, 1 is accepted

Sort by
0
Zamel
Top achievements
Rank 1
answered on 04 Apr 2013, 01:07 PM
A Telerik bug. Fixed in the Q1 2013 release.
Tags
GridView
Asked by
Zamel
Top achievements
Rank 1
Answers by
Zamel
Top achievements
Rank 1
Share this question
or