Back to Devexpress

DashboardDesigner.DashboardSaving Event

dashboard-devexpress-dot-dashboardwin-dot-dashboarddesigner-f61eb7c8.md

latest9.6 KB
Original Source

DashboardDesigner.DashboardSaving Event

Allows you to implement custom logic for dashboard saving.

Namespace : DevExpress.DashboardWin

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

NuGet Package : DevExpress.Win.Dashboard

Declaration

csharp
public event DashboardSavingEventHandler DashboardSaving
vb
Public Event DashboardSaving As DashboardSavingEventHandler

Event Data

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

PropertyDescription
CommandGets which user action raised the event.
DashboardGets the dashboard that should be saved.
HandledGets or sets whether default actions are required to save the dashboard.
SavedGets or sets whether the custom save routine has succeeded.

Remarks

The DashboardSaving event is raised when an end-user clicks the Save or Save As button. Handle this event to implement a custom saving procedure.

Use the DashboardSavingEventArgs.Dashboard property to obtain the dashboard that should be saved.

To determine whether the Save or Save As button has been pressed, use the DashboardSavingEventArgs.Command property.

After you have saved the dashboard, set the DashboardSavingEventArgs.Handled property to true. Otherwise, the dashboard will be saved using the default routine.

If your custom save procedure has not completed successfully, set the DashboardSavingEventArgs.Saved property to false to ensure that the DashboardDesigner handles this situation properly.

When an end-user creates or opens a dashboard, the DashboardDesigner raises the DashboardDesigner.DashboardCreating or DashboardDesigner.DashboardOpening 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:

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

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

csharp
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);
        }
    }
}
vb
Imports DevExpress.LookAndFeel
Imports DevExpress.XtraEditors
Imports System.Windows.Forms

Namespace Dashboard_LoadingAndSaving
    Partial Public Class Form1
        Inherits DevExpress.XtraEditors.XtraForm

        Private filePath As String = "..\..\Data\DashboardDefinition.xml"

        Public Sub New()
            InitializeComponent()
            dashboardDesigner1.CreateRibbon()
        End Sub
        Private Sub dashboardDesigner1_DashboardSaving(ByVal sender As Object, ByVal e As DevExpress.DashboardWin.DashboardSavingEventArgs) Handles dashboardDesigner1.DashboardSaving
            If e.Command = DevExpress.DashboardWin.DashboardSaveCommand.Save Then
                dashboardDesigner1.Dashboard.SaveToXml(filePath)
                e.Handled = True
            End If
            If e.Command = DevExpress.DashboardWin.DashboardSaveCommand.SaveAs Then
                Dim result As DialogResult = InvokeMessageBox()
                If result = DialogResult.OK Then
                    dashboardDesigner1.Dashboard.SaveToXml(filePath)
                    e.Handled = True
                    e.Saved = True
                End If
                If result = DialogResult.Cancel Then
                    e.Handled = True
                    e.Saved = False
                End If
            End If
        End Sub
        Private Sub dashboardDesigner1_DashboardOpening(ByVal sender As Object, ByVal e As DevExpress.DashboardWin.DashboardOpeningEventArgs) Handles dashboardDesigner1.DashboardOpening
            dashboardDesigner1.LoadDashboard(filePath)
            e.Handled = True
        End Sub
        Public Function InvokeMessageBox() As DialogResult
            Return XtraMessageBox.Show(New UserLookAndFeel(dashboardDesigner1), "Do you want to save the dashboard to the default location?", "Save As", MessageBoxButtons.OKCancel)
        End Function
    End Class
End Namespace

See Also

Save a Dashboard in the WinForms Designer

DashboardDesigner Class

DashboardDesigner Members

DevExpress.DashboardWin Namespace