Back to Devexpress

GridContext Class

dashboard-devexpress-dot-dashboardwin-787360f0.md

latest5.6 KB
Original Source

GridContext Class

Provides a connection between data item containers from the Columns section and an underlying control’s columns.

Namespace : DevExpress.DashboardWin

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

NuGet Package : DevExpress.Win.Dashboard

Declaration

csharp
public class GridContext :
    ControlContext
vb
Public Class GridContext
    Inherits ControlContext

The following members return GridContext objects:

Remarks

The grid context provides the connection between dashboard data item containers from the Columns section and the underlying control’s columns. The GetControlColumn method returns a data item container that corresponds to the specified control’s column. The GetDashboardItemColumn method, in turn, gets a control’s column that corresponds to the specified data item container from the Columns section.

For example, the Grid dashboard item has dimension, measure and delta columns (data item containers in the Columns section). In this case, the underlying Grid control also displays three columns: State, Sales (Sum) and Sales vs Target. The image below shows these elements that define Grid context:

When you pass the State data item container as the GetControlColumn method parameter, you get a GridColumn column in return:

On the contrary, if you pass one of the GridColumn object as the GetDashboardItemColumn method parameter, you get a column (a data item container from the Columns section) in the selected Grid dashboard item that corresponds this control’s column:

The following code snippet shows how to set a back color for a Grid’s measure column. The DashboardDesigner.DashboardItemControlUpdated event is used to update the Grid’s appearance.

csharp
using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
using System.Drawing;

// ...

private void DashboardDesigner1_DashboardItemControlUpdated(object sender, DashboardItemControlEventArgs e) {
    if(e.GridControl != null) {
        DashboardDesigner designer = (DashboardDesigner)sender;
        var gridDashboardItem = designer.Dashboard.Items[e.DashboardItemName] as GridDashboardItem;
        foreach(var dashGridColumn in gridDashboardItem.Columns) {
            if(dashGridColumn is GridMeasureColumn && dashGridColumn != null) {
                var column = e.GridContext.GetGridControlColumn(dashGridColumn);
                column.AppearanceCell.BackColor = Color.LightCyan;
            }
        }            
    }
}
vb
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWin
Imports System.Drawing

' ...

Private Sub DashboardDesigner1_DashboardItemControlUpdated(ByVal sender As Object, ByVal e As DashboardItemControlEventArgs)
    If e.GridControl IsNot Nothing Then
        Dim designer As DashboardDesigner = CType(sender, DashboardDesigner)
        Dim gridDashboardItem = TryCast(designer.Dashboard.Items(e.DashboardItemName), GridDashboardItem)
        For Each dashGridColumn In gridDashboardItem.Columns
            If TypeOf dashGridColumn Is GridMeasureColumn AndAlso dashGridColumn IsNot Nothing Then
                Dim column = e.GridContext.GetGridControlColumn(dashGridColumn)
                column.AppearanceCell.BackColor = Color.LightCyan
            End If
        Next dashGridColumn
    End If
End Sub

Inheritance

Object ControlContext GridContext

See Also

GridContext Members

DevExpress.DashboardWin Namespace