dashboard-devexpress-dot-dashboardwin-dot-dashboarddesigner-854b7c49.md
Allows you to provide data for the DashboardObjectDataSource.
Namespace : DevExpress.DashboardWin
Assembly : DevExpress.Dashboard.v25.2.Win.dll
NuGet Package : DevExpress.Win.Dashboard
public event DataLoadingEventHandler DataLoading
Public Event DataLoading As DataLoadingEventHandler
The DataLoading event's data class is DataLoadingEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Data | Gets or sets data for the current data source. |
| DataId | Gets an object data source’s unique identifier. |
| DataSourceComponentName | Get the component name of the data source for which the event has been raised. |
| DataSourceName | Gets the name of the data source for which the event has been raised. |
| OverwriteDataSourceProperty | Specifies whether the DataSource and DataMember properties of the DashboardObjectDataSource are set when data is supplied in the event handler. |
| Parameters | Provides access to parameter values passed to the object data source. |
The DataLoading event is raised when the dashboard loads data from the DashboardObjectDataSource. Use the event parameter’s e.Data property to provide data for this data source. The data object should implement the IEnumerable or IListSource interface.
For other data source types (for instance, DashboardSqlDataSource or DashboardOlapDataSource), you can handle the DashboardDesigner.ConfigureDataConnection event to customize connection parameters.
Note
Asynchronous Mode
The DashboardDesigner.AsyncDataLoading and DashboardDesigner.DataLoading events in asynchronous mode may occur multiple times while you design a dashboard and change the dashboard object model. To improve performance, do not call time-consuming methods in the event handler.
This example demonstrates how to use the DashboardDesigner.DataLoading event to load the data from XML file at runtime.
It contains a dashboard bound to an object data source with fake data whose structure is defined by an XML schema. The actual data is loaded at runtime from an XML file.
To load the data, click the Load Data custom button in the dashboard title. The button is created by handling the CustomizeDashboardTitle event. Its click action calls the DashboardViewer.ReloadData method that triggers the DashboardViewer.DataLoading event. The actual data is obtained within the event handler and assigned to the e.Data property.
View Example: How to Load XML Data from a File at Runtime
using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
using DevExpress.XtraEditors;
using System;
using System.Data;
namespace Dashboard_DataLoading_Example {
public partial class Form1 : XtraForm {
string dataFileName = string.Empty;
public Form1() {
InitializeComponent();
dashboardViewer1.CustomizeDashboardTitle += DashboardViewer1_CustomizeDashboardTitle;
dashboardViewer1.Dashboard = new Dashboard1();
dashboardViewer1.DataLoading += DashboardViewer1_DataLoading;
}
private void DashboardViewer1_DataLoading(object sender, DataLoadingEventArgs e) {
if (e.DataSourceName == "EnergyConsumptionBySector") {
e.Data = GetData(dataFileName);
}
}
public DataTable GetData(string fileName) {
if (fileName == string.Empty) return null;
DataSet xmlDataSet = new DataSet();
xmlDataSet.ReadXml(fileName);
return xmlDataSet.Tables["CountriesBySector"];
}
private void DashboardViewer1_CustomizeDashboardTitle(object sender, CustomizeDashboardTitleEventArgs e) {
DashboardToolbarItem titleButton = new DashboardToolbarItem("Load Data",
new Action<DashboardToolbarItemClickEventArgs>((args) =>
{
LoadNewData();
}));
titleButton.Caption = "Load Data";
e.Items.Add(titleButton);
}
private void LoadNewData() {
dataFileName = @"..\..\Data\DashboardEnergyConsumptionBySector.xml";
dashboardViewer1.ReloadData();
}
}
}
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWin
Imports DevExpress.XtraEditors
Imports System
Imports System.Data
Namespace Dashboard_DataLoading_Example
Partial Public Class Form1
Inherits XtraForm
Private dataFileName As String = String.Empty
Public Sub New()
InitializeComponent()
AddHandler dashboardViewer1.CustomizeDashboardTitle, AddressOf DashboardViewer1_CustomizeDashboardTitle
dashboardViewer1.Dashboard = New Dashboard1()
AddHandler dashboardViewer1.DataLoading, AddressOf DashboardViewer1_DataLoading
End Sub
Private Sub DashboardViewer1_DataLoading(ByVal sender As Object, ByVal e As DataLoadingEventArgs)
If e.DataSourceName = "EnergyConsumptionBySector" Then
e.Data = GetData(dataFileName)
End If
End Sub
Public Function GetData(ByVal fileName As String) As DataTable
If fileName = String.Empty Then
Return Nothing
End If
Dim xmlDataSet As New DataSet()
xmlDataSet.ReadXml(fileName)
Return xmlDataSet.Tables("CountriesBySector")
End Function
Private Sub DashboardViewer1_CustomizeDashboardTitle(ByVal sender As Object, ByVal e As CustomizeDashboardTitleEventArgs)
Dim titleButton As DashboardToolbarItem = New DashboardToolbarItem("Load Data", New Action(Of DashboardToolbarItemClickEventArgs)(Sub(args)
LoadNewData()
End Sub))
titleButton.Caption = "Load Data"
e.Items.Add(titleButton)
End Sub
Private Sub LoadNewData()
dataFileName = "..\..\Data\DashboardEnergyConsumptionBySector.xml"
dashboardViewer1.ReloadData()
End Sub
End Class
End Namespace
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DataLoading 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.
dashboardDesigner1.DataSourceOptions.ObjectDataSourceLoadingBehavior = DevExpress.DataAccess.DocumentLoadingBehavior.LoadAsIs;
dashboardDesigner1.DataLoading += DashboardDesigner1_DataLoading;
dashboardDesigner1.AsyncDataLoading += DashboardDesigner1_AsyncDataLoading;
dashboardDesigner1.DataSourceOptions.ObjectDataSourceLoadingBehavior = DevExpress.DataAccess.DocumentLoadingBehavior.LoadAsIs
AddHandler dashboardDesigner1.DataLoading, AddressOf DashboardDesigner1_DataLoading
AddHandler dashboardDesigner1.AsyncDataLoading, AddressOf DashboardDesigner1_AsyncDataLoading
See Also