dashboard-devexpress-dot-dashboardwin-dot-dashboardviewer-fd619d12.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 needs to load data from a data source assigned using the DashboardObjectDataSource. Use the event parameter’s DataLoadingEventArgs.Data property to provide data for this data source. This object should implement the IEnumerable or IListSource interface.
For other data source types (for instance, DashboardSqlDataSource or DashboardOlapDataSource), you can handle the DashboardViewer.ConfigureDataConnection event to customize connection parameters.
The following example demonstrates how to bind a dashboard to a List object.
The quantity values are provided at runtime. The dashboard data source is added to the Dashboard.DataSources collection on the first load.
Click the Reload Data button to call the DashboardViewer.ReloadData method. It raises the DashboardViewer.DataLoading event and supplies the dashboard with updated data.
View Example: How to Bind a Dashboard to a List of Objects
using System;
using System.Collections.Generic;
using System.Threading;
namespace Dashboard_BindingToList {
public class Data {
public string SalesPerson { get; set; }
public int Quantity { get; set; }
public static List<Data> CreateData() {
List<Data> data = new List<Data>();
string[] salesPersons = { "Andrew Fuller", "Michael Suyama", "Robert King", "Nancy Davolio",
"Margaret Peacock", "Laura Callahan", "Steven Buchanan", "Janet Leverling" };
for (int i = 0; i < 100; i++) {
Data record = new Data();
int seed = (int)DateTime.Now.Ticks & 0x0000FFFF;
record.SalesPerson = salesPersons[new Random(seed).Next(0, salesPersons.Length)];
record.Quantity = new Random(seed).Next(0, 100);
data.Add(record);
Thread.Sleep(3);
}
return data;
}
}
}
using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
using DevExpress.DataAccess;
using DevExpress.XtraEditors;
using System;
namespace Dashboard_BindingToList {
public partial class Form1 : XtraForm {
public Form1() {
InitializeComponent();
dashboardViewer1.DataSourceOptions.ObjectDataSourceLoadingBehavior = DocumentLoadingBehavior.LoadAsIs;
dashboardViewer1.CustomizeDashboardTitle += DashboardViewer1_CustomizeDashboardTitle;
}
private void Form1_Load(object sender, System.EventArgs e) {
Dashboard dashboard = new Dashboard();
DashboardObjectDataSource dataSource = new DashboardObjectDataSource("Data Source 1");
dashboardViewer1.DataLoading += (s, ev) => {
if (ev.DataSourceName == "Data Source 1")
ev.Data = Data.CreateData();
};
dashboard.DataSources.Add(dataSource);
PieDashboardItem pies = new PieDashboardItem();
pies.DataSource = dashboard.DataSources[0];
Dimension salesPersonArgument = new Dimension("SalesPerson");
Measure quantity = new Measure("Quantity");
pies.Arguments.Add(salesPersonArgument);
salesPersonArgument.TopNOptions.Enabled = true; salesPersonArgument.TopNOptions.Count = 3;
salesPersonArgument.TopNOptions.Measure = quantity;
pies.Values.Add(quantity);
GridDashboardItem grid = new GridDashboardItem();
grid.DataSource = dashboard.DataSources[0];
grid.Columns.Add(new GridDimensionColumn(new Dimension("SalesPerson")));
grid.Columns.Add(new GridMeasureColumn(new Measure("Quantity")));
dashboard.Items.AddRange(pies, grid);
dashboardViewer1.Dashboard = dashboard;
}
private void DashboardViewer1_CustomizeDashboardTitle(object sender, CustomizeDashboardTitleEventArgs e)
{
DashboardToolbarItem titleButton = new DashboardToolbarItem("Load Data",
new Action<DashboardToolbarItemClickEventArgs>((args) =>
{
dashboardViewer1.ReloadData();
}));
titleButton.Caption = "Reload Data";
e.Items.Add(titleButton);
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Threading
Namespace Dashboard_BindingToList
Public Class Data
Public Property SalesPerson() As String
Public Property Quantity() As Integer
Public Shared Function CreateData() As List(Of Data)
'INSTANT VB NOTE: The variable data was renamed since it may cause conflicts with calls to static members of the user-defined type with this name:
Dim data_Renamed As New List(Of Data)()
Dim salesPersons() As String = { "Andrew Fuller", "Michael Suyama", "Robert King", "Nancy Davolio", "Margaret Peacock", "Laura Callahan", "Steven Buchanan", "Janet Leverling" }
For i As Integer = 0 To 99
Dim record As New Data()
Dim seed As Integer = CInt(Date.Now.Ticks And &HFFFF)
record.SalesPerson = salesPersons((New Random(seed)).Next(0, salesPersons.Length))
record.Quantity = (New Random(seed)).Next(0, 100)
data_Renamed.Add(record)
Thread.Sleep(3)
Next i
Return data_Renamed
End Function
End Class
End Namespace
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWin
Imports DevExpress.DataAccess
Imports DevExpress.XtraEditors
Imports System
Namespace Dashboard_BindingToList
Partial Public Class Form1
Inherits XtraForm
Public Sub New()
InitializeComponent()
dashboardViewer1.DataSourceOptions.ObjectDataSourceLoadingBehavior = DocumentLoadingBehavior.LoadAsIs
AddHandler dashboardViewer1.CustomizeDashboardTitle, AddressOf DashboardViewer1_CustomizeDashboardTitle
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dashboard As New Dashboard()
Dim dataSource As New DashboardObjectDataSource("Data Source 1")
AddHandler dashboardViewer1.DataLoading, Sub(s, ev)
If ev.DataSourceName = "Data Source 1" Then
ev.Data = Data.CreateData()
End If
End Sub
dashboard.DataSources.Add(dataSource)
Dim pies As New PieDashboardItem()
pies.DataSource = dashboard.DataSources(0)
Dim salesPersonArgument As New Dimension("SalesPerson")
Dim quantity As New Measure("Quantity")
pies.Arguments.Add(salesPersonArgument)
salesPersonArgument.TopNOptions.Enabled = True
salesPersonArgument.TopNOptions.Count = 3
salesPersonArgument.TopNOptions.Measure = quantity
pies.Values.Add(quantity)
Dim grid As New GridDashboardItem()
grid.DataSource = dashboard.DataSources(0)
grid.Columns.Add(New GridDimensionColumn(New Dimension("SalesPerson")))
grid.Columns.Add(New GridMeasureColumn(New Measure("Quantity")))
dashboard.Items.AddRange(pies, grid)
dashboardViewer1.Dashboard = dashboard
End Sub
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)
dashboardViewer1.ReloadData()
End Sub))
titleButton.Caption = "Reload Data"
e.Items.Add(titleButton)
End Sub
End Class
End Namespace
The following code snippets (auto-collected from DevExpress Examples) contain references 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.
DashboardObjectDataSource dataSource = new DashboardObjectDataSource("Data Source 1");
dashboardViewer1.DataLoading += (s, ev) => {
if (ev.DataSourceName == "Data Source 1")
InitializeComponent();
dashboardViewer1.DataLoading += dashboardViewer1_DataLoading;
dashboardViewer1.DashboardItemClick += dashboardViewer1_DashboardItemClick;
dashboardViewer1.Dashboard = new Dashboard1();
dashboardViewer1.DataLoading += DashboardViewer1_DataLoading;
}
Dim dataSource As New DashboardObjectDataSource("Data Source 1")
AddHandler dashboardViewer1.DataLoading, Sub(s, ev)
If ev.DataSourceName = "Data Source 1" Then
InitializeComponent()
AddHandler dashboardViewer1.DataLoading, AddressOf dashboardViewer1_DataLoading
AddHandler dashboardViewer1.DashboardItemClick, AddressOf dashboardViewer1_DashboardItemClick
dashboardViewer1.Dashboard = New Dashboard1()
AddHandler dashboardViewer1.DataLoading, AddressOf DashboardViewer1_DataLoading
End Sub
See Also