Capture a report event on the Parent Windows Form

I need the ReportViewer object to interact with the Parent Form that hosts it. For instance, if I click a row in the report's table, how can I update a property on the host form Is this possible

This is a windows application in C#.



Answer this question

Capture a report event on the Parent Windows Form

  • TwilightBrigade

    The post was helpful, but a little vague. I did additional research and found this article by Teo Lachev:

    http://www.devx.com/dotnet/Article/30424/1954 pf=true

    The section of interest is at the bottom of the article "Implementing a custom navigation action". This goes into more detail describing the "Jump to Url" property. It is found by Right-Clicking the field you need to link, choosing Properties, then the Navigation tab. I found that you cannot simply reference the field value you need, but a workaround is to format it like this (for example):

    ="customerid:" & Fields!CustomerID.Value

    Without the "customerid:" part, the link will not work.

    Finally, on the parent form, create the eventhandler for the Hyperlink event of the reportviewer object. By using the HyperlinkEventArgs which are passed during the link event, you can get the value for your parent form:

    private void reportViewer_Hyperlink(object sender, HyperlinkEventArgs e)
    {
    Uri uri = new Uri(e.Hyperlink);
    if (uri.Scheme.ToLower() == "customerid")
    {
    e.Cancel = true;
    // Load the customer details in another form
    ((ReportViewer)sender).RefreshReport();
    }
    }

    Hope this helps someone down the line!


  • Tsayers

    There are a number of events on the report viewer control that you can handle to perform custom actions in your form.  Most users have had the most success my adding hyperlinks to the report, then handling the ReportViewer.Hyperlink event by cancelling the event and performing a custom action.
  • Capture a report event on the Parent Windows Form