The requested page is not available for the requested platform. You are viewing the content for Default platform.

How to: Bind a Dashboard to a DataSet Populated from an XML File

  • 3 min to read

To learn how to bind a dashboard to the Object data source using the Dashboard Designer, see Binding to Object Data Sources.

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.

Imports System
Imports System.Data
Imports DevExpress.XtraEditors
Imports DevExpress.DashboardCommon

Namespace Dashboard_DataLoading
    Partial Public Class Form1
        Inherits XtraForm

        Public Sub New()
        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()
            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")))
        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()
            Return xmlDataSet.Tables("Cars")
        End Function

        Public Function UpdateData() As DataTable
            Dim xmlDataSet As New DataSet()
            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.
        End Sub
    End Class
End Namespace
See Also