DashboardViewer.SetDashboardState(DashboardState) Method
Applies the dashboard state to the loaded dashboard.
Namespace: DevExpress.DashboardWin
Assembly: DevExpress.Dashboard.v19.2.Win.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
state | DashboardState | A DashboardState object that contains the dashboard state information. |
Example
Note
The complete sample project How to Set the Initial Dashboard State in the WinForms Viewer is available in the DevExpress Examples repository.
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
{
DashboardState dState = new DashboardState();
const string path = @"..\..\Dashboards\dashboardWithSavedState.xml";
public ViewerForm1() {
InitializeComponent();
dashboardViewer.DashboardLoaded += dashboardViewer_DashboardLoaded;
dashboardViewer.SetInitialDashboardState += dashboardViewer_SetInitialDashboardState;
dashboardViewer.DashboardSource = path;
}
private void dashboardViewer_DashboardLoaded(object sender,
DevExpress.DashboardWin.DashboardLoadedEventArgs e) {
XElement data = e.Dashboard.UserData;
if(data != null) {
if(data.Element("DashboardState") != null) {
XDocument dStateDocument = XDocument.Parse(data.Element("DashboardState").Value);
dState.LoadFromXml(XDocument.Parse(data.Element("DashboardState").Value));
}
}
}
private void dashboardViewer_SetInitialDashboardState(object sender,
DevExpress.DashboardWin.SetInitialDashboardStateEventArgs e) {
e.InitialState = dState;
}
private void ViewerForm1_FormClosing(object sender,FormClosingEventArgs e) {
dState = dashboardViewer.GetDashboardState();
XElement userData = new XElement("Root",
new XElement("DateModified",DateTime.Now),
new XElement("DashboardState",dState.SaveToXml().ToString(SaveOptions.DisableFormatting)));
dashboardViewer.Dashboard.UserData = userData;
dashboardViewer.Dashboard.SaveToXml(path);
}
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SetDashboardState(DashboardState) method.
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.