ActiveReports 6 Online Help Send comments on this topic.
Add Hyperlinks
See Also
ActiveReports 6 > ActiveReports User Guide > How To > Add Hyperlinks

Glossary Item Box

Using the Hyperlink property available on the following ActiveReports controls, you can add hyperlinks that connect to a Web page, open an e-mail, or jump to a bookmark.

To link to a Web page

  1. Click the control to select it. 
  2. In the Properties window, set the HyperLink property to any valid URL.

To link to an e-mail address

  1. Click the control to select it.
  2. In the Properties window, set the HyperLink property to mailto: and any valid e-mail address.

To parse the URL out of a database field for a hyperlink

  1. Double-click the section where the control is located. This creates an event-handling method for the section's Format event.
  2. Add code to the Format event to
    • Parse the URL out of the HomePage field
    • Assign it to the HyperLink property of txtHomePage
    • Remove the URL markers from the text displayed in txtHomePage

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

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Format event. Copy Code
Dim iStart As Integer
Dim sHTML As String
If txtHomePage.Text <> "" Then
    iStart = InStr(1, txtHomePage.Text, "#", CompareMethod.Text)
    sHTML = Right(txtHomePage.Text, (Len(txtHomePage.Text) - iStart))
    sHTML = Replace(sHTML, "#", "", 1, -1, CompareMethod.Text)
    txtHomePage.HyperLink = sHTML
    txtHomePage.Text = Replace(txtHomePage.Text, "#", "", 1, -1, CompareMethod.Text)
End If

ShowTo write the code in C#

C# code. Paste INSIDE the Format event. Copy Code
int iStart;
string sHTML;
if (txtHomePage.Text != "")
    {
     iStart = txtHomePage.Text.IndexOf("#",0);
     sHTML = txtHomePage.Text.Substring(iStart, txtHomePage.Text.Length - iStart);
     sHTML = sHTML.Replace("#", "");
     txtHomePage.HyperLink = sHTML;
     txtHomePage.Text = txtHomePage.Text.Replace("#", "");
    }

To create a hyperlink that jumps to a bookmark

  1. Double-click the section where the control is located. This creates an event-handling method for the section's Format event.
  2. Add code to the Format event to
    • Parse the URL out of the HomePage field
    • Assign it to the HyperLink property of txtHomePage
    • Remove the URL markers from the text displayed in txtHomePage

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

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste JUST ABOVE the Format event. Copy Code
Public pBM As New BookmarksCollection()
Dim iEntry As Integer
Visual Basic.NET code. Paste INSIDE the Format event. Copy Code
Me.Detail1.AddBookmark(Me.txtCompanyName.Text)
Me.txtEntry.HyperLink = "toc://" + pBM(iEntry - 1).Label
Me.txtEntry.Text = pBM(iEntry - 1).Label     
Me.txtPage.Text = pBM(iEntry - 1).PageNumber

ShowTo write the code in C#

C# code. Paste JUST ABOVE the Format event. Copy Code
public BookmarksCollection pBM = new BookmarksCollection();
int iEntry;
C# code. Paste INSIDE the Format event. Copy Code
this.detail.AddBookmark(this.txtCompanyName.Text);
this.txtEntry.HyperLink = "toc://" + pBM[iEntry - 1].Label;
this.txtEntry.Text = pBM[iEntry - 1].Label;
this.txtPage.Text = pBM[iEntry - 1].PageNumber.ToString();

To display the page number of the bookmark in the table of contents

ShowTo write the code in Visual Basic

  1. At the top left of the code view for the report, click the drop-down arrow and select (YourReportName Events).
  2. At the top right of the code window, click the drop-down arrow and select FetchData. This creates an event-handling method for the report's FetchData event.
  3. Add code to the handler to retrieve information to populate the report fields.

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

Visual Basic.NET code. Paste INSIDE the FetchData event. Copy Code
If iEntry > pBM.Count - 1 Then
    eArgs.EOF = True
Else
    eArgs.EOF = False
    iEntry += 1
End If

ShowTo write the code in C#

  1. Back in design view, click in the gray area below the report to select it.
  2. Click the events icon in the Properties window to display available events for the report.
  3. Double-click FetchData. This creates an event-handling method for the report's FetchData event.
  4. Add code to the handler to retrieve information to populate the report fields.

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

C# code. Paste INSIDE the FetchData event. Copy Code
if (iEntry > pBM.Count - 1)
{
    eArgs.EOF = true;
}
else
{
    eArgs.EOF = false;
    iEntry += 1;
}

See Also