DashboardDesigner.DataLoading Event
Allows you to provide data for the DashboardObjectDataSource.
Namespace: DevExpress.DashboardWin
Assembly: DevExpress.Dashboard.v19.1.Win.dll
Declaration
Event Data
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. |
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. |
Parameters | Provides access to parameter values passed to the object data source. |
Remarks
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 DashboardDesigner.ConfigureDataConnection event to customize connection parameters.
Example
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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-bind-a-dashboard-to-a-dataset-populated-from-an-xml-file-e4857.
Imports System
Imports System.Data
Imports DevExpress.XtraEditors
Imports DevExpress.DashboardCommon
Namespace Dashboard_DataLoading
Partial Public Class Form1
Inherits XtraForm
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Dim dashboard As New Dashboard()
Dim objectDataSource As New DashboardObjectDataSource()
objectDataSource.DataSource = GetData()
objectDataSource.Fill()
dashboard.DataSources.Add(objectDataSource)
dashboardViewer1.Dashboard = dashboard
' Creates a new grid dashboard item with two columns that display car models and prices.
Dim grid1 As New GridDashboardItem()
grid1.DataSource = dashboard.DataSources(0)
grid1.Columns.Add(New GridDimensionColumn(New Dimension("Model")))
grid1.Columns.Add(New GridMeasureColumn(New Measure("Price")))
dashboard.Items.Add(grid1)
End Sub
' Handles the DashboardViewer.DataLoading event to provide the dashboard with new data.
Private Sub dashboardViewer1_DataLoading(ByVal sender As Object, _
ByVal e As DataLoadingEventArgs) _
Handles dashboardViewer1.DataLoading
If e.DataSourceName = "Object Data Source 1" Then
e.Data = UpdateData()
End If
End Sub
Public Function GetData() As DataTable
Dim xmlDataSet As New DataSet()
xmlDataSet.ReadXml("..\..\Data\Cars_1.xml")
Return xmlDataSet.Tables("Cars")
End Function
Public Function UpdateData() As DataTable
Dim xmlDataSet As New DataSet()
xmlDataSet.ReadXml("..\..\Data\Cars_2.xml")
Return xmlDataSet.Tables("Cars")
End Function
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
' Reloads data in data sources.
dashboardViewer1.ReloadData()
End Sub
End Class
End Namespace