dashboard-devexpress-dot-dashboardwin-dot-dashboardviewer-22818e13.md
Handle this event to get the dashboard item data, and apply master filter and dashboard state in asynchronous mode.
Namespace : DevExpress.DashboardWin
Assembly : DevExpress.Dashboard.v25.2.Win.dll
NuGet Package : DevExpress.Win.Dashboard
public event EventHandler Initialized
Public Event Initialized As EventHandler
The Initialized event's data class is EventArgs.
This event indicates that you can safely access dashboard items, and allows you to manage filters and the dashboard state.
This example demonstrates how to work in asynchronous mode to get filter values, set the master filter and perform an asynchronous task when the dashboard is loaded for the first time.
Click Random Filter to get available filters and apply a random filter asynchronously.
using DevExpress.DashboardCommon.ViewerData;
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RandomFilterExample
{
public partial class ViewerForm1 : XtraForm {
public ViewerForm1() {
InitializeComponent();
dashboardViewer1.Initialized += OnDashboardViewerInitialized;
}
async void OnMouseClick(object sender, MouseEventArgs e) {
await RandomFilter();
}
async Task RandomFilter() {
string itemName = "choroplethMapDashboardItem1";
IList<AxisPointTuple> filters = await dashboardViewer1.GetAvailableFilterValuesAsync(itemName);
Random r = new Random();
int index = r.Next(0, filters.Count - 1);
await dashboardViewer1.SetMasterFilterAsync(itemName, filters[index]);
}
async void OnDashboardViewerInitialized(object sender, EventArgs e) {
await RandomFilter();
}
}
}
Imports DevExpress.DashboardCommon.ViewerData
Imports DevExpress.XtraEditors
Imports System
Imports System.Collections.Generic
Imports System.Threading.Tasks
Imports System.Windows.Forms
Namespace RandomFilterExample
Partial Public Class ViewerForm1
Inherits XtraForm
Public Sub New()
InitializeComponent()
AddHandler dashboardViewer1.Initialized, AddressOf OnDashboardViewerInitialized
End Sub
Private Async Overloads Sub OnMouseClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles simpleButton1.MouseClick
Await RandomFilter()
End Sub
Private Async Function RandomFilter() As Task
Dim itemName As String = "choroplethMapDashboardItem1"
Dim filters As IList(Of AxisPointTuple) = Await dashboardViewer1.GetAvailableFilterValuesAsync(itemName)
Dim r As New Random()
Dim index As Integer = r.Next(0, filters.Count - 1)
Await dashboardViewer1.SetMasterFilterAsync(itemName, filters(index))
End Function
Private Async Sub OnDashboardViewerInitialized(ByVal sender As Object, ByVal e As EventArgs)
Await RandomFilter()
End Sub
End Class
End Namespace
This example demonstrates how to get the data displayed in the dashboard item asynchronously when the dashboard is loaded.
The labels at the top display the data row count for the specified dashboard item.
using DevExpress.DashboardCommon;
using DevExpress.XtraEditors;
using System;
using System.Threading.Tasks;
namespace DataCounterExample
{
public partial class ViewerForm1 : XtraForm {
public ViewerForm1() {
InitializeComponent();
dashboardViewer1.Initialized += OnDashboardViewerInitialized;
dashboardViewer1.MasterFilterSet += OnDashboardViewerMasterFilterSet;
dashboardViewer1.MasterFilterCleared += OnDashboardViewerMasterFilterCleared;
}
async void OnDashboardViewerInitialized(object sender, EventArgs e) {
simpleLabelItem1.Text = await GetLabelText("choroplethMapDashboardItem1", "Map");
simpleLabelItem2.Text = await GetLabelText("gridDashboardItem1", "Grid");
}
async void OnDashboardViewerMasterFilterSet(object sender, MasterFilterSetEventArgs e) {
simpleLabelItem2.Text = await GetLabelText("gridDashboardItem1", "Grid");
}
async void OnDashboardViewerMasterFilterCleared(object sender, MasterFilterClearedEventArgs e) {
simpleLabelItem2.Text = await GetLabelText("gridDashboardItem1", "Grid");
}
async Task<string> GetLabelText(string itemName, string itemCaption) {
var data = await dashboardViewer1.GetItemDataAsync(itemName);
int count = data.GetAxisPoints(data.GetAxisNames()[0]).Count;
return string.Format("{0}: {1}", itemCaption, count);
}
}
}
Imports DevExpress.DashboardCommon
Imports DevExpress.XtraEditors
Imports System
Imports System.Threading.Tasks
Namespace DataCounterExample
Partial Public Class ViewerForm1
Inherits XtraForm
Public Sub New()
InitializeComponent()
AddHandler dashboardViewer1.Initialized, AddressOf OnDashboardViewerInitialized
AddHandler dashboardViewer1.MasterFilterSet, AddressOf OnDashboardViewerMasterFilterSet
AddHandler dashboardViewer1.MasterFilterCleared, AddressOf OnDashboardViewerMasterFilterCleared
End Sub
Private Async Sub OnDashboardViewerInitialized(ByVal sender As Object, ByVal e As EventArgs)
simpleLabelItem1.Text = Await GetLabelText("choroplethMapDashboardItem1", "Map")
simpleLabelItem2.Text = Await GetLabelText("gridDashboardItem1", "Grid")
End Sub
Private Async Sub OnDashboardViewerMasterFilterSet(ByVal sender As Object, ByVal e As MasterFilterSetEventArgs)
simpleLabelItem2.Text = Await GetLabelText("gridDashboardItem1", "Grid")
End Sub
Private Async Sub OnDashboardViewerMasterFilterCleared(ByVal sender As Object, ByVal e As MasterFilterClearedEventArgs)
simpleLabelItem2.Text = Await GetLabelText("gridDashboardItem1", "Grid")
End Sub
Private Async Function GetLabelText(ByVal itemName As String, ByVal itemCaption As String) As Task(Of String)
Dim data = Await dashboardViewer1.GetItemDataAsync(itemName)
Dim count As Integer = data.GetAxisPoints(data.GetAxisNames()(0)).Count
Return String.Format("{0}: {1}", itemCaption, count)
End Function
End Class
End Namespace
See Also