Glossary Item Box
ActiveReports allows Bookmarks to be easily set up and used in simple reports by adding code to the Detail_Format event of the report.
This walkthrough illustrates how to set up and use Bookmarks in a simple report.
This walkthrough is split up into the following activities:
To complete the walkthrough, you must have access to the NorthWind database (Nwind.mdb).
When you have completed this walkthrough, you will have a report that looks similar to the following.
To add an ActiveReport to your project
To connect the report to a data source
To add controls to the report
Control | DataField | Name | Text/Caption | Location |
---|---|---|---|---|
TextBox | ProductName | txtProductName | Product Name | 1.125, 0 |
TextBox | CategoryName | txtCategoryName | Category Name | 0, 0 |
TextBox | UnitsInStock | txtUnitsInStock | Units In Stock | 2.25, 0 |
TextBox | UnitsOnOrder | txtUnitsOnOrder | Units On Order | 3.375, 0 |
TextBox | UnitPrice | txtUnitPrice | Unit Price | 4.5, 0 |
To write the code in Visual Basic
To write the code in C#
The following example shows what the code for the method looks like.
' Visual Basic Private Sub Detail_Format(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ Detail.Format
Me.Detail.AddBookmark(txtCategoryName.text)
End Sub
//C#
private void Detail_Format(object sender, System.EventArgs eArgs)
{
Detail.AddBookmark(txtCategoryName.Text);
}
The following example shows what the code for the method looks like to set up leveled Bookmarks.
' Visual Basic Private Sub Detail_Format(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ Detail.Format
Me.Detail.AddBookmark(txtCategoryName.Text + "\" + txtProductName.Text)
End Sub
//C#
private void Detail_Format(object sender, System.EventArgs eArgs)
{
Detail.AddBookmark(txtCategoryName.Text + "\\" + txtProductName.Text);
}
To view the report
To view the Bookmarks collection
To create and add special bookmarks to the bookmarks collection at run time, you will need to add the bookmarks to the report document's pages collection since the bookmarks are generated from the pages collection.
' Visual Basic Private Sub Detail_Format(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ Detail.Format Dim i As Integer Try For i = 0 To Me.Document.Pages.Count - 1 Me.Document.Pages(1).AddBookmark("New Bookmark", 8) Next Catch ex As Exception End Try End Sub
//C#
private void Detail_Format(object sender, System.EventArgs eArgs) { for(int i = 0; i<Document.Pages.Count;i++) { this.Document.Pages[i].AddBookmark("New Bookmark", 25); } }
Note: Only add bookmarks at the Page level during report processing. Do not add or remove them using the BookmarksCollection methods until after the document is completely loaded into the viewer. This is because the viewer clears the BookmarksCollection and then recreates it using the bookmarks that are contained in each individual page.
See Also |
Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.