Skip to main content

DashboardDesigner.DashboardOpening Event

Allows you to implement custom logic for dashboard opening.

Namespace: DevExpress.DashboardWin

Assembly: DevExpress.Dashboard.v24.2.Win.dll

Declaration

public event DashboardOpeningEventHandler DashboardOpening

Event Data

The DashboardOpening event's data class is DashboardOpeningEventArgs. The following properties provide information specific to this event:

Property Description
Dashboard Gets or sets the dashboard that will be opened.
Handled Gets or sets whether the dashboard to be opened has been provided.

Remarks

The DashboardOpening event is raised when a when an end-user clicks the Open button. Handle this event to override the default Open File dialog and implement custom actions.

Assign the dashboard that should be opened to the event parameter’s DashboardOpeningEventArgs.Dashboard property.

After you have provided the dashboard, set the DashboardOpeningEventArgs.Handled property to true. Otherwise, the default actions will be performed, i.e., the Open File dialog will be invoked and the dashboard selected by the end-user will be opened.

When an end-user creates or saves a dashboard, the DashboardDesigner raises the DashboardDesigner.DashboardCreating or DashboardDesigner.DashboardSaving event respectively.

Example

The following example demonstrates how to implement custom saving and opening procedures in Dashboard Designer.

The Dashboard Designer allows you to override default opening and saving procedures in the following cases:

  • When a user clicks the Open, Save, or Save As buttons in the Ribbon:

    StoringDashboards_FileGroupButtons

  • When a user tries to save the dashboard using the Save Confirmation dialog when the window with the DashboardDesigner is closed.

    SaveConfirmationDialog

To implement custom saving and opening procedures, you need to handle the DashboardDesigner.DashboardSaving and DashboardDesigner.DashboardOpening events.

In this example, the dashboard XML definition can be saved (opened) only to (from) the specified default location.

A custom saving routine is implemented in the DashboardDesigner.DashboardSaving event handler. Its e.Command event parameter allows determining what user action raises the event. The Dashboard.SaveToXml method is used to save the dashboard to the specified XML file. Then, the e.Handled event parameter is used to specify that the dashboard has been saved and no default actions are required.

Clicking the Save As button invokes a message box that allows saving the dashboard to the default location or cancel the saving procedure. The e.Saved event parameter is used to notify whether the custom saving routine has succeeded.

The DashboardDesigner.DashboardOpening event handler implements a custom opening procedure. The DashboardDesigner.LoadDashboard method is called to load the dashboard from the default location. The e.Handled event parameter allows specifying that no default actions are required to open the dashboard.

View Example

using DevExpress.LookAndFeel;
using DevExpress.XtraEditors;
using System.Windows.Forms;

namespace Dashboard_LoadingAndSaving {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        string filePath = @"..\..\Data\DashboardDefinition.xml";

        public Form1() {
            InitializeComponent();
            dashboardDesigner1.CreateRibbon();
        }
        private void dashboardDesigner1_DashboardSaving(object sender, 
            DevExpress.DashboardWin.DashboardSavingEventArgs e) {
            if (e.Command == DevExpress.DashboardWin.DashboardSaveCommand.Save) {
                dashboardDesigner1.Dashboard.SaveToXml(filePath);
                e.Handled = true;
            }
            if (e.Command == DevExpress.DashboardWin.DashboardSaveCommand.SaveAs) {
                DialogResult result = InvokeMessageBox();
                if (result == DialogResult.OK) {
                    dashboardDesigner1.Dashboard.SaveToXml(filePath);
                    e.Handled = true;
                    e.Saved = true;
                }
                if (result == DialogResult.Cancel) {
                    e.Handled = true;
                    e.Saved = false;
                }
            }
        }
        private void dashboardDesigner1_DashboardOpening(object sender, 
            DevExpress.DashboardWin.DashboardOpeningEventArgs e) {
            dashboardDesigner1.LoadDashboard(filePath);
            e.Handled = true;
        }
        public DialogResult InvokeMessageBox() {
            return XtraMessageBox.Show(new UserLookAndFeel(dashboardDesigner1),
                                       "Do you want to save the dashboard to the default location?",
                                       "Save As",
                                       MessageBoxButtons.OKCancel);
        }
    }
}
See Also