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

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

The following example demonstrates how to bind a dashboard to a DataSet populated from an XML file.

In this example, an XML file provides data about car models and corresponding prices. The data source is created for the 'Cars' data table and added to the Dashboard.DataSources collection on the first load.

To update the displayed data, the DashboardViewer.ReloadData method is called. This raises the DashboardDesigner.DataLoading event and allows supplying the dashboard with updated data.

´╗┐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