6th March 2015

DevExpress – Run Report Straight From Navigation

DevExpress – Run Report Straight From Navigation

As described in one of my previous DevExpress articles, it is possible to open a detail view straight from the navigation menu while loading the relevant record to be displayed, this is useful for tables which will only ever contain one record e.g. System Configuration records which can never be created or deleted and there will only ever be one record making the list view unnecessary.

The above method and logic is also available for running reports straight from the navigation or from an action button placed within a toolbar. The following code below is an adaptation of the code in the previous article however it will allow you to run a DevExpress V2 Report which is stored within the database straight from a navigation item when clicked. I have also added some error handling in the form of a User Friendly Exception, which will be thrown if the report could not be found within the database, which will be a more user friendly error than the standard “Object Reference Error”.

using System;
using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.ReportsV2;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.Persistent.BaseImpl;
 
/// <summary>
/// Navigation Window Controller
/// </summary>
public partial class NavigationWindowController : WindowController

/// <summary> /// Initializes a new instance of the <see cref="NavigationWindowController"/> class. /// </summary> public NavigationWindowController()

this.TargetWindowType = WindowType.Main;

/// <summary> /// Called when [activated]. /// </summary> protected override void OnActivated()

base.OnActivated(); Frame.GetController<ShowNavigationItemController>().CustomShowNavigationItem += new EventHandler<CustomShowNavigationItemEventArgs>(this.Report_CustomShowNavigationItem);

/// <summary> /// Called when [deactivated]. /// </summary> protected override void OnDeactivated()

base.OnDeactivated(); Frame.GetController<ShowNavigationItemController>().CustomShowNavigationItem -= new EventHandler<CustomShowNavigationItemEventArgs>(this.Report_CustomShowNavigationItem);

/// <summary> /// Handles the CustomShowNavigationItem event of the SystemConfiguration control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="CustomShowNavigationItemEventArgs"/> instance containing the event data.</param> private void Report_CustomShowNavigationItem(object sender, CustomShowNavigationItemEventArgs e)

if (e.ActionArguments.SelectedChoiceActionItem.Id == "NavigationItemIdHere")

IObjectSpace objectSpace = Application.CreateObjectSpace(); ReportDataV2 report = objectSpace.FindObject<ReportDataV2>(CriteriaOperator.Parse("DisplayName = 'Report name Here'")); if (report != null)

string handle = ReportDataProvider.ReportsStorage.GetReportContainerHandle(report); Frame.GetController<ReportServiceController>().ShowPreview(handle); e.Handled = true;

else

throw new UserFriendlyException("The report could not be found, please contact your system administrator.");

Fill in this quick form and discover your digital future
Choose your interests:

Where to find us

We'd love to welcome you into our office! We're only 20 miles north of Peterborough, conveniently just off the A16.

Carver House
Apex Court, Elsoms Way
Pinchbeck
Lincolnshire
PE11 3UL