Back to Devexpress

DashboardViewer.SetInitialDashboardState Event

dashboard-devexpress-dot-dashboardwin-dot-dashboardviewer-697cf4db.md

latest12.3 KB
Original Source

DashboardViewer.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.

Examples

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

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

csharp
using DevExpress.DashboardCommon;
using DevExpress.XtraEditors;
using System;
using System.Windows.Forms;
using System.Xml.Linq;

namespace WinFormsViewerSaveAndApplyDashboardState
{
    public partial class ViewerForm1: XtraForm
    {
        public static readonly string PropertyName = "DashboardState";
        const string path = @"..\..\Dashboards\dashboardWithSavedState.xml";
        public ViewerForm1() {
            InitializeComponent();
            dashboardViewer.SetInitialDashboardState += dashboardViewer_SetInitialDashboardState;
            dashboardViewer.DashboardSource = 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 dashboardViewer_SetInitialDashboardState(object sender,
            DevExpress.DashboardWin.SetInitialDashboardStateEventArgs e) {
            var state = GetDataFromString(dashboardViewer.Dashboard.CustomProperties.GetValue(PropertyName));
            e.InitialState = state;
        }

        private void ViewerForm1_FormClosing(object sender,FormClosingEventArgs e) {
            var dState = dashboardViewer.GetDashboardState();
            var stateValue = dState.SaveToXml().ToString(SaveOptions.DisableFormatting);
            dashboardViewer.Dashboard.CustomProperties.SetValue("DashboardState", stateValue);
            dashboardViewer.Dashboard.SaveToXml(path);
        }
    }
}
vb
Imports DevExpress.DashboardCommon
Imports DevExpress.XtraEditors
Imports System
Imports System.Windows.Forms
Imports System.Xml.Linq

Namespace WinFormsViewerSaveAndApplyDashboardState
    Partial Public Class ViewerForm1
        Inherits XtraForm
        Public Shared ReadOnly PropertyName As String = "DashboardState"
        Private Const path As String = "..\..\Dashboards\dashboardWithSavedState.xml"
        Public Sub New()
            InitializeComponent()
            AddHandler dashboardViewer.SetInitialDashboardState, AddressOf dashboardViewer_SetInitialDashboardState
            dashboardViewer.DashboardSource = 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 dashboardViewer_SetInitialDashboardState(ByVal sender As Object, ByVal e As DevExpress.DashboardWin.SetInitialDashboardStateEventArgs)
            Dim state = GetDataFromString(dashboardViewer.Dashboard.CustomProperties.GetValue(PropertyName))
            e.InitialState = state
        End Sub

        Private Sub ViewerForm1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
            Dim dState = dashboardViewer.GetDashboardState()
            Dim stateValue = dState.SaveToXml().ToString(SaveOptions.DisableFormatting)
            dashboardViewer.Dashboard.CustomProperties.SetValue("DashboardState", stateValue)
            dashboardViewer.Dashboard.SaveToXml(path)
        End Sub
    End Class
End Namespace

The following example shows how to specify default parameter values when a dashboard is loading.

To do this, handle the DashboardViewer.SetInitialDashboardState event. Create a DashboardParameterState instance and use its Name and Value properties to configure parameter settings. Create a DashboardState object and add the specified dashboard parameter to the DashboardState.Parameters collection. Assign the created DashboardState object to the SetInitialDashboardStateBaseEventArgs.InitialState property to apply specified parameter values when a dashboard is loading.

View Example

csharp
using System.Collections.Generic;
using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
using DevExpress.DataAccess.ConnectionParameters;

namespace WinViewer_DefaultParameterValues {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            InitializeComponent();
        }
        private void dashboardViewer1_SetInitialDashboardState(object sender, SetInitialDashboardStateEventArgs e) {
            DashboardState state = new DashboardState();
            DashboardParameterState parameters = new DashboardParameterState();
            parameters.Name = "customerIdParameter";
            parameters.Value = new List<string>() { "ALFKI", "AROUT", "BONAP" };
            state.Parameters.Add(parameters);
            e.InitialState = state;
        }
        private void dashboardViewer1_ConfigureDataConnection(object sender, DashboardConfigureDataConnectionEventArgs e) {
            if (e.DataSourceName == "SQL Data Source 1")
                e.ConnectionParameters = new Access97ConnectionParameters(@"..\..\Data\nwind.mdb", "", "");
        }
    }
}
vb
Imports System.Collections.Generic
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWin
Imports DevExpress.DataAccess.ConnectionParameters

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

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub dashboardViewer1_SetInitialDashboardState(ByVal sender As Object, ByVal e As SetInitialDashboardStateEventArgs)
            Dim state As New DashboardState()
            Dim parameters As New DashboardParameterState()
            parameters.Name = "customerIdParameter"
            parameters.Value = New List(Of String)() From {"ALFKI", "AROUT", "BONAP"}
            state.Parameters.Add(parameters)
            e.InitialState = state
        End Sub

        Private Sub dashboardViewer1_ConfigureDataConnection(ByVal sender As Object, ByVal e As DashboardConfigureDataConnectionEventArgs) Handles dashboardViewer1.ConfigureDataConnection
            If e.DataSourceName = "SQL Data Source 1" Then
                e.ConnectionParameters = New Access97ConnectionParameters("..\..\Data\nwind.mdb", "", "")
            End If
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references 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-dashboard-save-restore-dashboard-state/CS/WinFormsDashboard_DashboardState/Form1.cs#L18

csharp
InitializeComponent();
dashboardViewer1.SetInitialDashboardState += DashboardViewer1_SetInitialDashboardState;
dashboardViewer1.ConfigureDataConnection += DashboardViewer1_ConfigureDataConnection;

winforms-viewer-save-and-apply-dashboard-state/CS/WinFormsViewerSaveAndApplyDashboarState/ViewerForm1.cs#L15

csharp
InitializeComponent();
dashboardViewer.SetInitialDashboardState += dashboardViewer_SetInitialDashboardState;
dashboardViewer.DashboardSource = path;

winforms-dashboard-save-restore-dashboard-state/VB/WinFormsDashboard_DashboardState/Form1.vb#L16

vb
InitializeComponent()
AddHandler dashboardViewer1.SetInitialDashboardState, AddressOf DashboardViewer1_SetInitialDashboardState
AddHandler dashboardViewer1.ConfigureDataConnection, AddressOf DashboardViewer1_ConfigureDataConnection

winforms-viewer-save-and-apply-dashboard-state/VB/WinFormsViewerSaveAndApplyDashboarState/ViewerForm1.vb#L14

vb
InitializeComponent()
AddHandler dashboardViewer.SetInitialDashboardState, AddressOf dashboardViewer_SetInitialDashboardState
dashboardViewer.DashboardSource = path

Implements

SetInitialDashboardState

See Also

GetDashboardState()

SetDashboardState(DashboardState)

DashboardStateChanged

Manage Dashboard State in the WinForms Viewer Control

DashboardViewer Class

DashboardViewer Members

DevExpress.DashboardWin Namespace