Skip to main content
A newer version of this page is available. .

How to: Modify a Dashboard Item at Runtime

  • 2 minutes to read

This example demonstrates how to change the data source field specified for the chart argument in the Chart Dashboard Item.

Dashboard items are contained in the Dashboard.Items collection. Iterate through the collection and find an item with the required ComponentName (which is unique in a dashboard) or an item of the desired type. To find an item of the particular type, you can use type conversion operators and check for successful conversion.

When you find a dashboard item, cast it to the proper type and use properties of that type.

In this example, the DashboardViewer.Dashboard property is used to get access to a dashboard loaded in the Dashboard Viewer control.

A LINQ query obtains all dashboard items of the Chart type from the Dashboard.Items collection. The DashboardItem object is converted to the ChartDashboardItem type. The ChartDashboardItem.GetDimensions method obtains a list of all chart’s dimensions. Finally, the dimension’s data member value “Category” is replaced with “State”.

Note

The complete sample project How to Modify a Dashboard Item at Runtime is available in the DevExpress Examples repository.

 // Change the argument's data source field from "Category" to "State" in all chart items.
Dashboard dBoard = dashboardViewer.Dashboard;
foreach (DashboardItem item in dBoard.Items.Where(x => x is ChartDashboardItem)) {
    ChartDashboardItem chart = (ChartDashboardItem)item;
    foreach (var dimension in chart.GetDimensions().Where(d => d.DataMember == "Category"))
        dimension.DataMember = "State";
}