DashboardDesigner.DataLoading Event

Allows you to provide data for the DashboardObjectDataSource.

Namespace: DevExpress.DashboardWin

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

Declaration

public event DataLoadingEventHandler DataLoading
Public Event DataLoading As DataLoadingEventHandler

Event Data

The DataLoading event handler receives an argument of the DataLoadingEventArgs type. 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.
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.

Examples

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

The complete sample project How to Load XML Data from a File at Runtime is available in the DevExpress Examples repository.

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

Implements

DevExpress.DashboardWin.Native.IClientSideApi.DataLoading
See Also