Skip to main content

DashboardDesigner.DataLoading Event

Allows you to provide data for the DashboardObjectDataSource.

Namespace: DevExpress.DashboardWin

Assembly: DevExpress.Dashboard.v24.2.Win.dll

Declaration

public event DataLoadingEventHandler DataLoading

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.
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.

Remarks

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.

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.

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();
        }
    }
}

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.

Implements

See Also