New to Telerik Reporting? Download free 30-day trial

Custom Actions Overview

A custom action is an action that contains a collection of parameters, defined by the user, that will be evaluated during report processing. It does not affect the currently viewed report in any way - its purpose is to be used in a report viewer's interactive action event handlers: InteractiveActionExecuting(), InteractiveActionEnter() and InteractiveActionLeave().

To define a CustomAction use the Edit Action Dialog or create it programmatically in the report class body.

Here is an example of how to get the custom action's parameters in the InteractiveActionExecuting event of the WinForms Report Viewer.

void reportViewer1_CustomInteractiveActionExecuting(object sender, Telerik.ReportViewer.Common.InteractiveActionCancelEventArgs args)
{
    var strB = new System.Text.StringBuilder();
    strB.AppendLine("ReportItem name: " + args.Action.ReportItemName);

    var customAction = args.Action as Telerik.Reporting.Processing.CustomAction;
    if (null != customAction)
    {
        foreach (var p in customAction.Parameters)
        {
            strB.AppendLine(string.Format("Parameter \"{0}\" value: {1}", p.Key, p.Value));
        }
    }

    strB.AppendLine(string.Format("Mouse cursor position: {0}; Item bounds: {1}", args.CursorPos, args.Bounds));

    MessageBox.Show(strB.ToString());
}
' Handles the InteractiveActionExecuting event
' Do not forget to add the WithEvents clause on ReportViewer1 instantiation if needed.
Private Sub reportViewer1_CustomInteractiveActionExecuting(sender As Object, args As Telerik.ReportViewer.Common.InteractiveActionCancelEventArgs) Handles ReportViewer1.InteractiveActionExecuting

    Dim strB = New System.Text.StringBuilder()
    strB.AppendLine("ReportItem name: " + args.Action.ReportItemName)

    Dim customAction = TryCast(args.Action, Telerik.Reporting.Processing.CustomAction)
    If customAction IsNot Nothing Then
        For Each p As KeyValuePair(Of String, Object) In customAction.Parameters
            strB.AppendLine(String.Format("Parameter ""{0}"" value: {1}", p.Key, p.Value))
        Next
    End If

    strB.AppendLine(String.Format("Mouse cursor position: {0}; Item bounds: {1}", args.CursorPos, args.Bounds))

    MessageBox.Show(strB.ToString())
End Sub

How to Add a Custom Action

Adding a custom action using the Report Designer

  1. In Design view, right-click the report item to which you want to add a link and then click Properties.

  2. In The Properties dialog box for that report item, click Action. The Edit Action dialog will open.

  3. Select Custom. An additional section appears in the dialog box, containing a button titled Select parameters.

  4. Clicking the button will open the Edit Custom Action Parameters dialog box. Add one or more parameters, defining their Name and Value properties.

  5. Click OK when ready.

  6. To test the action, preview the report and click the report item with the applied custom action. A message will appear, displaying information for the action's properties.

Adding a custom action programatically

Telerik.Reporting.CustomAction customAction = new Telerik.Reporting.CustomAction();
customAction.Parameters.Add("param1", "=Fields.Name");
customAction.Parameters.Add("param2", "=Now()");
textBox1.Action = customAction;
Dim customAction As New Telerik.Reporting.CustomAction()
customAction.Parameters.Add("param1", "=Fields.Name")
customAction.Parameters.Add("param2", "=Now()")
textBox1.Action = customAction

See Also

In this article