Skip to main content

DashboardViewer.SetInitialDashboardState Event

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

Namespace: DevExpress.DashboardWin

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

NuGet Package: DevExpress.Win.Dashboard

Declaration

public event SetInitialDashboardStateEventHandler SetInitialDashboardState

Event Data

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

Property Description
Dashboard A dashboard whose state can be initialized. Inherited from SetInitialDashboardStateBaseEventArgs.
InitialState Gets 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:

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

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

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", "", "");
        }
    }
}

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.

See Also