Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

Access the Dashboard Control

  • 4 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 WinForms module project (MySolution.Module.Win) references the DevExpress.Dashboard.v21.2.Win.dll and DevExpress.ExpressApp.Dashboards.Win.v21.2.dll assemblies;
  • your ASP.NET Web Forms module project (MySolution.Module.Web) references the DevExpress.Dashboard.v21.2.Web.dll and DevExpress.ExpressApp.Dashboards.Web.v21.2.dll assemblies.
  • your ASP.NET Core Blazor module project (MySolution.Module.Blazor) references the DevExpress.ExpressApp.Dashboards.Blazor.21.2 NuGet package.

WinForms and ASP.NET Web Forms Applications

Follow the steps below in WinForms and ASP.NET Web Forms module projects to access the dashboard control:

  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.

WinForms
File: MySolution.Module.Win\Controllers\WinDashboardController.cs(.vb).

using System;
using DevExpress.DashboardWin;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Dashboards.Win;
using DevExpress.Persistent.Base;
// ...
public class WinDashboardController : ObjectViewController<DetailView, IDashboardData> {
    private WinDashboardViewerViewItem dashboardViewerViewItem;
    protected override void OnActivated() {
        base.OnActivated();
        dashboardViewerViewItem = View.FindItem("DashboardViewer") as WinDashboardViewerViewItem;
        if(dashboardViewerViewItem != null) {
            if(dashboardViewerViewItem.Viewer != null) {
                CustomizeDashboardViewer(dashboardViewerViewItem.Viewer);
            }
            else {
                dashboardViewerViewItem.ControlCreated += DashboardViewerViewItem_ControlCreated;
            }
        }
    }
    private void DashboardViewerViewItem_ControlCreated(object sender, EventArgs e) {
        CustomizeDashboardViewer(((WinDashboardViewerViewItem)sender).Viewer);
    }
    private void CustomizeDashboardViewer(DashboardViewer dashboardViewer) {
        dashboardViewer.AllowPrintDashboardItems = true;
    }
    protected override void OnDeactivated() {
        if(dashboardViewerViewItem != null) {
            dashboardViewerViewItem.ControlCreated -= DashboardViewerViewItem_ControlCreated;
            dashboardViewerViewItem = null;
        }
        base.OnDeactivated();
    }
}

ASP.NET Web Forms
File: MySolution.Module.Web\Controllers\WebDashboardController.cs(.vb).

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();
    }
}

ASP.NET Core Blazor Applications

Follow the steps below in a Blazor module project (MySolution.Module.Blazor) to access the DxDashboard component model. A component model is the representation of 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: How to: Implement a Property Editor Based on a Custom Component (Blazor).

  1. Add a Controller activated in the IDashboardData Detail Views.
  2. In the Controller’s OnActivated method, use the CustomizeViewItemControl<T>(DetailView, Controller, Action<T>) extension method to customize the BlazorDashboardViewerViewItem before the DxDashboard component is rendered. Declare the additional CustomizeDashboardViewerViewItem method and customize the View Item in it.
  3. In the CustomizeDashboardViewerViewItem method, cast the View Item’s Control property value to DevExpress.ExpressApp.Dashboards.Blazor.Components.DxDashboardViewerAdapter and access its ComponentModel property.

The following example demonstrates how to set the default dashboard working mode to Designer.

using DevExpress.DashboardWeb;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Dashboards.Blazor.Components;
using DevExpress.ExpressApp.Dashboards.Blazor.Components.Models;
using DevExpress.Persistent.Base;
// ...
public class BlazorDashboardController : ObjectViewController<DetailView, IDashboardData> {
    protected override void OnActivated() {
        base.OnActivated();
        View.CustomizeViewItemControl<BlazorDashboardViewerViewItem>(this, CustomizeDashboardViewerViewItem);
    }
    void CustomizeDashboardViewerViewItem(BlazorDashboardViewerViewItem dashboardViewerViewItem) {
        if(dashboardViewerViewItem.Control is DxDashboardViewerAdapter dashboardViewerAdapter) {
            SetWorkingMode(dashboardViewerAdapter.ComponentModel);
        }
    }
    private void SetWorkingMode(DxDashboardModel dxDashboardModel) {
        dxDashboardModel.WorkingMode = WorkingMode.Designer;
    }
}