Back to Devexpress

DataDashboardItem.DataSource Property

dashboard-devexpress-dot-dashboardcommon-dot-datadashboarditem.md

latest10.0 KB
Original Source

DataDashboardItem.DataSource Property

Gets or sets a data source to which the dashboard item is bound.

Namespace : DevExpress.DashboardCommon

Assembly : DevExpress.Dashboard.v25.2.Core.dll

NuGet Package : DevExpress.Dashboard.Core

Declaration

csharp
[DefaultValue(null)]
public IDashboardDataSource DataSource { get; set; }
vb
<DefaultValue(Nothing)>
Public Property DataSource As IDashboardDataSource

Property Value

TypeDefaultDescription
IDashboardDataSourcenull

An object implementing the IDashboardDataSource interface that specifies a data source to which the dashboard item is bound.

|

Remarks

All data-aware dashboard items expose the DataSource property that specifies a data source to which this item is actually bound. The DataDashboardItem.DataMember property specifies the required data member in this data source.

To access the collection of existing dashboard data sources, use the Dashboard.DataSources property.

Note

For DashboardSqlDataSource or DashboardEFDataSource, specify the required data member using the DataDashboardItem.DataMember property.

Example

The following code snippet demonstrates how to bind a Choropleth Map dashboard item to data in code.

csharp
using System.Windows.Forms;
using DevExpress.DashboardCommon;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;

namespace Dashboard_CreateChoroplethMap {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm
    {
        public Form1() {
            InitializeComponent();

            Dashboard dashboard = new Dashboard();

            DashboardSqlDataSource dataSource = new DashboardSqlDataSource();
            CustomSqlQuery sqlQuery = new CustomSqlQuery("Countries", "select * from Countries");
            dataSource.ConnectionParameters = new Access97ConnectionParameters(@"..\..\Data\countriesDB.mdb", "", "");
            dataSource.Queries.Add(sqlQuery);

            ChoroplethMapDashboardItem choroplethMap = new ChoroplethMapDashboardItem();
            choroplethMap.DataSource = dataSource;
            choroplethMap.DataMember = "Countries";

            choroplethMap.Area = ShapefileArea.WorldCountries;

            choroplethMap.AttributeName = "NAME";
            choroplethMap.AttributeDimension = new Dimension("Country");

            ValueMap populationMap = new ValueMap(new Measure("Population"));
            choroplethMap.Maps.Add(populationMap);

            dashboard.Items.Add(choroplethMap);
            dashboardViewer1.Dashboard = dashboard;
        }
    }
}
vb
Imports System.Windows.Forms
Imports DevExpress.DashboardCommon
Imports DevExpress.DataAccess.ConnectionParameters
Imports DevExpress.DataAccess.Sql

Namespace Dashboard_CreateChoroplethMap
    Partial Public Class Form1
        Inherits DevExpress.XtraEditors.XtraForm

        Public Sub New()
            InitializeComponent()

            Dim dashboard As New Dashboard()

            Dim dataSource As New DashboardSqlDataSource()
            Dim sqlQuery As New CustomSqlQuery("Countries", "select * from Countries")
            dataSource.ConnectionParameters = New Access97ConnectionParameters("..\..\Data\countriesDB.mdb", "", "")
            dataSource.Queries.Add(sqlQuery)

            Dim choroplethMap As New ChoroplethMapDashboardItem()
            choroplethMap.DataSource = dataSource
            choroplethMap.DataMember = "Countries"

            choroplethMap.Area = ShapefileArea.WorldCountries

            choroplethMap.AttributeName = "NAME"
            choroplethMap.AttributeDimension = New Dimension("Country")

            Dim populationMap As New ValueMap(New Measure("Population"))
            choroplethMap.Maps.Add(populationMap)

            dashboard.Items.Add(choroplethMap)
            dashboardViewer1.Dashboard = dashboard
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the DataSource property.

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.

winforms-dashboard-replace-sql-data-source-with-object-data-source-with-filtered-data/CS/WinFormsDashboard/ViewerForm.cs#L32

csharp
e.Dashboard.DataSources.Add(ods);
foreach (var item in e.Dashboard.Items.OfType<DataDashboardItem>().Where(i => i.DataSource == query.DataSource && i.DataMember == query.Query.Name)) {
    item.DataMember = "";

winforms-dashboard-designer-bind-a-dashboard-to-a-list-object/CS/Dashboard_BindingToList/Form1.cs#L26

csharp
PieDashboardItem pies = new PieDashboardItem();
pies.DataSource = dashboard.DataSources[0];
Dimension salesPersonArgument = new Dimension("SalesPerson");

winforms-dashboard-designer-merge-dashboards-to-tabs/CS/DashboardMerger/ItemsMerger.cs#L64

csharp
DataDashboardItem dataDashboardItem = dashboardItemCopy as DataDashboardItem;
if(dataDashboardItem != null && dataDashboardItem.DataSource != null) {
    string newDataSourceName = String.Empty;

winforms-dashboard-bind-to-entity-framework-data-source-at-runtime/CS/Dashboard_EntityFramework/Form1.cs#L21

csharp
pivot.DataMember = "Orders";
pivot.DataSource = dashboard.DataSources[0];
pivot.Rows.AddRange(new Dimension("ShipCountry"), new Dimension("ShipCity"));

winforms-dashboard-json-data-source/CS/DashboardJsonExample/Form1.cs#L28

csharp
PivotDashboardItem pivot = new PivotDashboardItem();
pivot.DataSource = jsonDataSource;
pivot.Rows.Add(new Dimension("ContactTitle"));

winforms-dashboard-designer-bind-a-dashboard-to-a-list-object/VB/Dashboard_BindingToList/Form1.vb#L29

vb
Dim pies As New PieDashboardItem()
pies.DataSource = dashboard.DataSources(0)
Dim salesPersonArgument As New Dimension("SalesPerson")

winforms-dashboard-designer-merge-dashboards-to-tabs/VB/DashboardMerger/ItemsMerger.vb#L70

vb
Dim dataDashboardItem As DataDashboardItem = TryCast(dashboardItemCopy, DataDashboardItem)
If dataDashboardItem IsNot Nothing AndAlso dataDashboardItem.DataSource IsNot Nothing Then
    Dim newDataSourceName As String = String.Empty

winforms-dashboard-bind-to-entity-framework-data-source-at-runtime/VB/Dashboard_EntityFramework/Form1.vb#L22

vb
pivot.DataMember = "Orders"
pivot.DataSource = dashboard.DataSources(0)
pivot.Rows.AddRange(New Dimension("ShipCountry"), New Dimension("ShipCity"))

winforms-dashboard-json-data-source/VB/DashboardJsonExample/Form1.vb#L26

vb
Dim pivot As New PivotDashboardItem()
pivot.DataSource = jsonDataSource
pivot.Rows.Add(New Dimension("ContactTitle"))

winforms-dashboard-data-federation/VB/DataFederationExample/Form1.vb#L42

vb
pivot.DataMember = "FDS-Created-by-NodeBulder"
pivot.DataSource = federatedDS_Join
pivot.Rows.AddRange(New Dimension("CategoryName"), New Dimension("ProductName"))

See Also

DataDashboardItem Class

DataDashboardItem Members

DevExpress.DashboardCommon Namespace