Back to Devexpress

DashboardDesigner.SetInitialDashboardState Event

dashboard-devexpress-dot-dashboardwin-dot-dashboarddesigner-28c7b27f.md

latest8.3 KB
Original Source

DashboardDesigner.SetInitialDashboardState Event

Allows you to specify the initial dashboard state when loading a dashboard.

Namespace : DevExpress.DashboardWin

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

NuGet Package : DevExpress.Win.Dashboard

Declaration

csharp
public event SetInitialDashboardStateEventHandler SetInitialDashboardState
vb
Public Event SetInitialDashboardState As SetInitialDashboardStateEventHandler

Event Data

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

PropertyDescription
DashboardA dashboard whose state can be initialized. Inherited from SetInitialDashboardStateBaseEventArgs.
InitialStateGets or sets the dashboard initial state. Inherited from SetInitialDashboardStateBaseEventArgs.

Remarks

Refer to the Manage Dashboard State document for more information about a dashboard state.

Example

View Example: How to Set the Initial Dashboard State in the WinForms Designer

The following code snippet shows how to save and restore a dashboard state for WinForms Dashboard Designer:

csharp
using DevExpress.DashboardCommon;
using System;
using System.Xml.Linq;

namespace WinDesignerDashboardState
{
    public partial class DesignerForm1: DevExpress.XtraBars.Ribbon.RibbonForm {
        public static readonly string PropertyName = "DashboardState";
        const string path = @"..\..\Dashboards\dashboardWithSavedState.xml";
        public DesignerForm1() {
            InitializeComponent();
            dashboardDesigner.DashboardClosing += dashboardDesigner_DashboardClosing;
            dashboardDesigner.SetInitialDashboardState += dashboardDesigner_SetInitialDashboardState;
            dashboardDesigner.CreateRibbon();
            dashboardDesigner.LoadDashboard(path);
        }

        DashboardState GetDataFromString(string customPropertyValue) {
            DashboardState dState = new DashboardState();
            if(!string.IsNullOrEmpty(customPropertyValue)) {
                var xmlStateEl = XDocument.Parse(customPropertyValue);
                dState.LoadFromXml(xmlStateEl);
            }
            return dState;
        }
        private void dashboardDesigner_SetInitialDashboardState(object sender,
            DevExpress.DashboardWin.SetInitialDashboardStateEventArgs e) {
            var state = GetDataFromString(dashboardDesigner.Dashboard.CustomProperties.GetValue(PropertyName));
            e.InitialState = state;
        }

        private void dashboardDesigner_DashboardClosing(object sender,DevExpress.DashboardWin.DashboardClosingEventArgs e) {
            var dState = dashboardDesigner.GetDashboardState();
            var stateValue = dState.SaveToXml().ToString(SaveOptions.DisableFormatting);
            dashboardDesigner.Dashboard.CustomProperties.SetValue("DashboardState", stateValue);
            dashboardDesigner.Dashboard.SaveToXml(path);
        }
    }
}
vb
Imports DevExpress.DashboardCommon
Imports System
Imports System.Xml.Linq

Namespace WinDesignerDashboardState
    Partial Public Class DesignerForm1
        Inherits DevExpress.XtraBars.Ribbon.RibbonForm
        Private Const path As String = "..\..\Dashboards\dashboardWithSavedState.xml"
        Public Shared ReadOnly PropertyName As String = "DashboardState"
        Public Sub New()
            InitializeComponent()
            AddHandler dashboardDesigner.DashboardClosing, AddressOf dashboardDesigner_DashboardClosing
            AddHandler dashboardDesigner.SetInitialDashboardState, AddressOf dashboardDesigner_SetInitialDashboardState
            dashboardDesigner.CreateRibbon()
            dashboardDesigner.LoadDashboard(path)
        End Sub
        Private Function GetDataFromString(ByVal customPropertyValue As String) As DashboardState
            Dim dState As New DashboardState()
            If (Not String.IsNullOrEmpty(customPropertyValue)) Then
                Dim xmlStateEl = XDocument.Parse(customPropertyValue)
                dState.LoadFromXml(xmlStateEl)
            End If
            Return dState
        End Function

        Private Sub dashboardDesigner_SetInitialDashboardState(ByVal sender As Object, ByVal e As DevExpress.DashboardWin.SetInitialDashboardStateEventArgs)
            Dim state = GetDataFromString(dashboardDesigner.Dashboard.CustomProperties.GetValue(PropertyName))
            e.InitialState = state
        End Sub

        Private Sub dashboardDesigner_DashboardClosing(ByVal sender As Object, ByVal e As DevExpress.DashboardWin.DashboardClosingEventArgs)
            Dim dState = dashboardDesigner.GetDashboardState()
            Dim stateValue = dState.SaveToXml().ToString(SaveOptions.DisableFormatting)
            dashboardDesigner.Dashboard.CustomProperties.SetValue("DashboardState", stateValue)
            dashboardDesigner.Dashboard.SaveToXml(path)
        End Sub
    End Class
End Namespace

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SetInitialDashboardState event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-designer-save-and-apply-dashboard-state/CS/WinDesignerDashboardState/DesignerForm1.cs#L13

csharp
dashboardDesigner.DashboardClosing += dashboardDesigner_DashboardClosing;
dashboardDesigner.SetInitialDashboardState += dashboardDesigner_SetInitialDashboardState;
dashboardDesigner.CreateRibbon();

winforms-designer-save-and-apply-dashboard-state/VB/WinDesignerDashboardState/DesignerForm1.vb#L13

vb
AddHandler dashboardDesigner.DashboardClosing, AddressOf dashboardDesigner_DashboardClosing
AddHandler dashboardDesigner.SetInitialDashboardState, AddressOf dashboardDesigner_SetInitialDashboardState
dashboardDesigner.CreateRibbon()

Implements

SetInitialDashboardState

See Also

GetDashboardState()

SetDashboardState(DashboardState)

DashboardStateChanged

Manage Dashboard State in the WinForms Designer Control

DashboardDesigner Class

DashboardDesigner Members

DevExpress.DashboardWin Namespace