Back to Devexpress

DashboardViewer.DashboardStateChanged Event

dashboard-devexpress-dot-dashboardwin-dot-dashboardviewer-875b3256.md

latest4.9 KB
Original Source

DashboardViewer.DashboardStateChanged Event

Occurs after the current dashboard state in the DashboardViewer is changed.

Namespace : DevExpress.DashboardWin

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

NuGet Package : DevExpress.Win.Dashboard

Declaration

csharp
public event DashboardStateChangedEventHandler DashboardStateChanged
vb
Public Event DashboardStateChanged As DashboardStateChangedEventHandler

Event Data

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

PropertyDescription
DashboardStateGets the current state of the dashboard.

Remarks

A dashboard state contains the selected master filter values, current drill-down levels, Range Filter and Date Filter settings, dashboard item layers and current parameter values. Use the DashboardStateChanged event to get the actual dashboard state - the latest interaction changes a user made to a dashboard. The DashboardState property provides access to the states of individual dashboard items displayed in the dashboard.

You can use the DashboardViewer.SetInitialDashboardState event to apply the state when a dashboard is loaded.

For more information about a dashboard state, see Manage Dashboard State.

Example

The following code snippet demonstrates how to save a dashboard state each time it is changed.

The DashboardViewer.GetDashboardState method obtains a dashboard’s state object in the DashboardStateChanged event that is handled each time the dashboard state is changed. The state is serialized to XML and added to the XElement object stored in the CustomProperties collection.

The dashboard state is restored in the DashboardViewer.SetInitialDashboardState event handler.

csharp
using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
// ...
DashboardState state = new DashboardState();
const string path = @"..\..\Dashboards\dashboard1.xml";
// ... 
private void DashboardViewer_DashboardStateChanged(object sender, DashboardStateChangedEventArgs e) {
  state = dashboardViewer.GetDashboardState();
  var stateValue = state.SaveToXml().ToString(SaveOptions.DisableFormatting);
  dashboardViewer.Dashboard.CustomProperties.SetValue("DashboardState", stateValue);          
}

private void DashboardViewer_SetInitialDashboardState(object sender, SetInitialDashboardStateEventArgs e) {
  e.InitialState = state;
}
// ...
vb
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWin
' ...
Private state As New DashboardState()
Private Const path As String = "..\..\Dashboards\dashboard1.xml"
' ...
Private Sub DashboardViewer_DashboardStateChanged(ByVal sender As Object, ByVal e As DashboardStateChangedEventArgs)
  state = dashboardViewer.GetDashboardState()
  Dim stateValue = state.SaveToXml().ToString(SaveOptions.DisableFormatting)
  dashboardViewer.Dashboard.CustomProperties.SetValue("DashboardState", stateValue)
End Sub

Private Sub DashboardViewer_SetInitialDashboardState(ByVal sender As Object, ByVal e As SetInitialDashboardStateEventArgs)
  e.InitialState = state
End Sub
' ...

Implements

DashboardStateChanged

See Also

SetInitialDashboardState

Manage Dashboard State in the WinForms Viewer Control

DashboardViewer Class

DashboardViewer Members

DevExpress.DashboardWin Namespace