ActiveReports 10
Add Bookmarks
ActiveReports 10 > ActiveReports User Guide > How To > Section Report How To > Add Bookmarks

In a section report, you can display bookmarks and nested bookmarks in the viewer's table of contents for fields, groups, and subreports. You can also add special bookmarks at run time.

To set up basic bookmarks

  1. From the Visual Studio toolbox, drag and drop a TextBox control onto the detail section.
  2. Double-click the Detail section of the report. This creates an event-handling method for the report's Detail_Format event.
  3. Add code to the handler to set up bookmarks.

The following example shows what the code for the method looks like.

To write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Detail Format event. 
Copy Code
Me.Detail1.AddBookmark(textBox1.text)

To write the code in C#

C# code. Paste INSIDE the Detail Format event.
Copy Code
Detail.AddBookmark(TextBox1.Text);

To set up leveled or nested bookmarks

  1. From the Report Explorer, drag and drop CustomerID and ContactName onto the detail section.
  2. Double-click the Detail section of the report. This creates an event-handling method for the report's Detail_Format event.
  3. Add code to the handler to set up bookmarks.

The following example shows what the code to set up leveled or nested Bookmarks looks like.

To write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Detail Format event.
Copy Code
Me.Detail1.AddBookmark(txtCustomerID.Text + "\" + txtContactName.Text)

To write the code in C#

C# code. Paste INSIDE the Detail Format event.
Copy Code
detail.AddBookmark(txtCustomerID.Text + "\\" + txtContactName.Text);

To nest grandchild bookmarks and use bookmarks in grouping

  1. From the Report Explorer, drag and drop CustomerID, ContactName and City fields onto the detail section.
  2. Double-click in the Detail section of the report. This creates an event-handling method for the report's Detail_Format event.
  3. Add code to the handler to set up a bookmark for each ContactName and nest ContactName bookmarks within each CustomerID, and CustomerID bookmarks in each City.

    The following example shows what the code for the detail section looks like.

    To write the code in Visual Basic.NET

    Visual Basic.NET code. Paste INSIDE the Detail_Format event.
    Copy Code
    Me.Detail1.AddBookmark(txtCity.Text + "\" + txtCustomerID.Text + "\" + txtContactName.Text)

    To write the code in C#

    C# code. Paste INSIDE the Detail_Format event.
    Copy Code
    this.detail.AddBookmark(txtCity.Text + "\\" + txtCustomerID.Text + "\\" + txtContactName.Text);
  4. Add a GroupHeader section to the layout and set its DataField property to City.
  5. Double-click in the Group Header section of the report. This creates an event-handling method for the report's Group Header Format event.
  6. Add code to the handler to set up a bookmark for each instance of the City group.

    The following example shows what the code for the group header looks like.

    To write the code in Visual Basic.NET

    Visual Basic.NET code. Paste INSIDE the Group Header Format event.
    Copy Code
    Me.GroupHeader1.AddBookmark(txtCity.Text)

    To write the code in C#

    C# code. Paste INSIDE the Group Header Format event.
    Copy Code
    this.groupHeader1.AddBookmark(txtCity.Text);

To combine parent report and subreport bookmarks

  1. From the Report Explorer, drag and drop the CustomerID field onto the detail section of the Parent report.
  2. Double-click the Detail section to create an event-handling method for the report's Detail Format event.
  3. Add code to the handler to create a bookmark for each instance of the CustomerID field in the main report.

    The following example shows what the code for the method looks like for the main report.

    To write the code in Visual Basic.NET

    Visual Basic.NET code. Paste INSIDE the Detail Format event of the main report.
    Copy Code
    Me.Detail1.AddBookmark(txtCustomerID.Text)

    To write the code in C#

    C# code. Paste INSIDE the Detail Format event of the main report.
    Copy Code
    detail1.AddBookmark(txtCustomerID.Text);
  4. From the Report Explorer, drag and drop the ContactName field onto the detail section of the Subreport.
  5. Double-click in the Detail section to create an event-handling method for the report's Detail Format event.
  6. Add code to the handler to create a bookmark for each instance of the ContactName field in the subreport.

    The following example shows what the code for the method looks like for the subreport.

    To write the code in Visual Basic.NET

    Visual Basic.NET code. Paste INSIDE the Detail Format event of the subreport.
    Copy Code
    Me.Detail1.AddBookmark(CType(Me.ParentReport.Sections("Detail1").Controls("txtCustomerID"), TextBox).Text + "\" + Me.txtContactName.Text)

    To write the code in C#

    C# code. Paste INSIDE the Detail Format event of the subreport.
    Copy Code
    this.detail1.AddBookmark(((TextBox)(this.ParentReport.Sections["Detail1"].Controls["txtCustomerID"])).Text + "\\" + this.txtContactName.Text);

To add special bookmarks at run time

To create and add special bookmarks to the bookmarks collection at run time, add the bookmarks to the report document's pages collection.

Caution: Remember that the page collection does not exist until the report runs, so use this code in the ReportEnd event or in form code after the report has run.

To write the code in Visual Basic.NET

  1. Click in the gray area outside the report and right-click to select Properties from the context menu.
  2. Click the Events icon in the Properties Window to display events available for the report.
  3. Double-click ReportEnd. This creates an event-handling method for the ReportEnd event.
  4. Add code to the handler to add a bookmark.

The following example shows what the code for the method looks like.

Visual Basic.NET code. Paste INSIDE the ReportEnd event.
Copy Code
Me.Document.Pages(0).AddBookmark("New Bookmark", 1)

To write the code in C#

C# code. Paste INSIDE the ReportEnd event.
Copy Code
this.Document.Pages[0].AddBookmark("New Bookmark", 1);

To view a report bookmarks in the Viewer or Preview tab

  1. Add the ActiveReports Viewer control to your Windows Form.
  2. Add code to display the report in the Viewer. See Viewing Reports for further information.
  3. Press F5 to run the report.
  4. On the Viewer toolbar, select Toggle Sidebar to open the sidebar and click the Document Map button to view the list of bookmarks.
See Also

Concepts