Skip to main content
.NET Framework 4.6.2+

Access the Dashboard Control

  • 3 minutes to read

This topic describes how to access the DashboardViewer control in a WinForms application, ASPxDashboard control in an ASP.NET Web Forms application, and the DxDashboard component model in an ASP.NET Core Blazor application.

Note

Refer to the following help topic for information on how to access the DashboardDesigner control: How to: Access the WinForms Dashboard Designer.

Important

Before you proceed, ensure that your platform-specific application project references the corresponding assemblies or NuGet packages:

  • WinForms: the DevExpress.Dashboard.v25.1.Win.dll and DevExpress.ExpressApp.Dashboards.Win.v25.1.dll assemblies;
  • ASP.NET Web Forms: the DevExpress.Dashboard.v25.1.Web.dll and DevExpress.ExpressApp.Dashboards.Web.v25.1.dll assemblies;
  • ASP.NET Core Blazor: the DevExpress.ExpressApp.Dashboards.Blazor.25.1 NuGet package.

ASP.NET Core Blazor Applications

To access the DxDashboard component model, follow the steps below in the ASP.NET Core Blazor application project (MySolution.Blazor.Server) and WinForms application project (MySolution.Win). A component model defines a Blazor component in code. When you modify the model, the underlying component reflects these changes. Refer to the following help topic for more information on component models: Underlying Controls and Components Behind UI Elements (ASP.NET Core Blazor).

  1. Add a Controller activated in the Dashboard Views.
  2. In the Controller’s OnActivated method, use the CustomizeViewItemControl<T>(DashboardView, Controller, Action<T>) extension method to customize the BlazorDashboardViewerViewItem before the DxDashboard component is rendered.
  3. In the CustomizeViewItemControl method access the BlazorDashboardViewerViewItem.ComponentModel property (in ASP.NET Core Blazor applications) or WinDashboardViewerViewItem.Viewer (in Windows Forms applications).

The following code snippet sets the default dashboard working mode to Designer:

File:
MySolution.Blazor.Server\Controllers\BlazorDashboardController.cs

using DevExpress.DashboardWeb;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Dashboards.Blazor.Components;
using DevExpress.Persistent.Base;

namespace MySolution.Blazor.Server.Controllers;
public class BlazorDashboardController : ViewController<DashboardView> {
    protected override void OnActivated() {
        base.OnActivated();
        View.CustomizeViewItemControl<BlazorDashboardViewerViewItem>(this, item => {
            item.ComponentModel.WorkingMode = WorkingMode.Designer;
        });
    }
}

Tip

To access and customize Dashboard View Item controls, use the CustomizeViewItemControl<T>(DashboardView, Controller, Action<T>) method.

The following code snippet enables Dashboard data printing:

WinForms

File:
MySolution.Win\Controllers\WinDashboardController.cs

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Dashboards.Win;

namespace MainDemo.Win.Controllers;
public class WinDashboardController : ViewController<DashboardView> {
    protected override void OnActivated() {
        base.OnActivated();
        View.CustomizeViewItemControl<WinDashboardViewerViewItem>(this, item => {
            if (item.Control != null) {
                var dashboardViewer = ((WinDashboardViewerViewItem)item).Viewer;
                if (dashboardViewer != null) {
                    dashboardViewer.AllowPrintDashboardItems = true;
                }
            }
        });
    }
}

ASP.NET Web Forms Applications

To access the dashboard control, follow the steps below in the ASP.NET Web Forms module project (MySolution.Module.Web).

  1. Add a Controller that activates for IDashboardData Detail Views.
  2. In the Controller’s OnActivated method, use the CompositeView.FindItem method to find the View Item with the “DashboardViewer” identifier.
  3. Handle the ViewItem.ControlCreated event and use the WinDashboardViewerViewItem.Viewer (WinForms) or WebDashboardViewerViewItem.DashboardControl property (ASP.NET Web Forms) to access the dashboard control.

ASP.NET Web Forms

File:
MySolution.Module.Web\Controllers\WebDashboardController.cs

using System;
using DevExpress.DashboardWeb;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Dashboards.Web;
using DevExpress.Persistent.Base;
// ...
public class WebDashboardController : ObjectViewController<DetailView, IDashboardData> {
    private WebDashboardViewerViewItem dashboardViewerViewItem;
    protected override void OnActivated() {
        base.OnActivated();
        dashboardViewerViewItem = View.FindItem("DashboardViewer") as WebDashboardViewerViewItem;
        if(dashboardViewerViewItem != null) {
            if(dashboardViewerViewItem.DashboardControl != null) {
                SetHeight(dashboardViewerViewItem.DashboardControl);
            }
            else {
                dashboardViewerViewItem.ControlCreated += DashboardViewerViewItem_ControlCreated;
            }
        }
    }
    private void DashboardViewerViewItem_ControlCreated(object sender, EventArgs e) {
        SetHeight(((WebDashboardViewerViewItem)sender).DashboardControl);
    }
    private void SetHeight(ASPxDashboard dashboardControl) {
        dashboardControl.Height = 760;
    }
    protected override void OnDeactivated() {
        if(dashboardViewerViewItem != null) {
            dashboardViewerViewItem.ControlCreated -= DashboardViewerViewItem_ControlCreated;
            dashboardViewerViewItem = null;
        }
        base.OnDeactivated();
    }
}
See Also