Ticket T161313
Visible to All Users

Display a control's page number in the report header

created 10 years ago

Hi,

In my report header (page 2) I need to write a text similar to the following:
"For detailed information on the subject go to page [Page Number]."

whilst I can create a hyperlink to jump to the page (the first control on the page), I cannot work out how I can specify the correct [Page Number] in the text - as the page number of destination varies between reports based on the data.

Could you please help?

Thanks in advance!

Answers approved by DevExpress Support

created 10 years ago (modified 10 years ago)

Hi Sergey,

It is impossible to get the required page number during the report generation process, because the referenced page is not yet generated. There are two possible solutions:

  1. Generate the Report document twice. On the first iteration, collect all required page indices. On the second iteration, pass these page indices to corresponding header controls.
  2. Iterate through all bricks in the resulting document to find the required entries. Once you have found Bricks, get the currently processed Page index and pass it to the original Brick's text. To iterate through the bricks, use the NestedBrickIterator class as follows:
C#
foreach (Page page in report.Pages) { NestedBrickIterator iterator = new NestedBrickIterator(page.InnerBricks); while (iterator.MoveNext()) if (iterator.CurrentBrick is VisualBrick) { VisualBrick brick = iterator.CurrentBrick as VisualBrick; ...... } }

Please let me know if you have further questions.

Posted by Sergey Poberezovskiy:
In case anyone else wants to see the solution, it is as follows:

C#
public override void CreateDocument(bool buildPagesInBackground) { base.CreateDocument(false); // I need to force the page creation - as otherwise there may not be any pages to iterate below: IRichTextBrick rtf = null; foreach (Page page in Pages) { NestedBrickIterator iterator = new NestedBrickIterator(page.InnerBricks); while (iterator.MoveNext()) { var brick = iterator.CurrentBrick as VisualBrick; if (brick == null) continue; if (myRtfControl.Equals(brick.BrickOwner)) // my condition { rtf = brick as IRichTextBrick; break; } else if (myReferencePageControl.Equals(brick.BrickOwner)) { // replace the text rtf.RtfText = rtf.RtfText.Replace("#pageNumber#", (page.Index + 1).ToString()); return; } } } }
    Show previous comments (1)
    DevExpress Support Team 10 years ago

      Hi Sergey,

      I see you are combining these two approaches, while I meant that you need to use one of them.
      To generate the resulting document twice, simply call the Report.CreateDocument method. I suggest that you review the following tickets that demonstrate one of possible ways to create a document twice:
      Increase height of all XRLabels to same as Detail height when one label forces detail to grow
      PageHeader PrintOn - NotWithGroupHeader

      As for setting the rtfPageText.Rtf property value, the resulting document "does not know" about XRControls that were used to generate its content. Instead, it uses Bricks of different types. You need to change the VisualBrick.Text property instead of modifying the XRControl properties.

      SP SP
      Sergey Poberezovskiy 10 years ago

        Hi Ingvar,
        Thank you for your help - I have modified the CreateDocument method as per your advice.
        In case anyone else wants to see the solution, it is as follows:
        public override void CreateDocument(bool buildPagesInBackground)
        {
        base.CreateDocument(false); // I need to force the page creation - as otherwise there may not be any pages to iterate below:
        IRichTextBrick rtf = null;
        foreach (Page page in Pages)
        {
        NestedBrickIterator iterator = new NestedBrickIterator(page.InnerBricks);
        while (iterator.MoveNext())
        {
        var brick = iterator.CurrentBrick as VisualBrick;
        if (brick == null)
        continue;
        if (myRtfControl.Equals(brick.BrickOwner)) // my condition
        {
        rtf = brick as IRichTextBrick;
        break;
        } else if (myReferencePageControl.Equals(brick.BrickOwner))
        {
        // replace the text
        rtf.RtfText = rtf.RtfText.Replace("#pageNumber#", (page.Index + 1).ToString());
        return;
        }
        }
        }
        }
        Sorry for no formatting - I do not know how to do it within the comment - Ingvar - could you please format it to help other potential readers?

        DevExpress Support Team 10 years ago

          Hi Sergey,

          Thank you for sharing your solution with us. I have re-posted it to my Answer to add formatting (currently comments do not support formatting code snippets).
          Feel free to contact us if you have further questions.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.