Back to Devexpress

FormatConditionExpression Class

dashboard-devexpress-dot-dashboardcommon-5c100f4c.md

latest6.4 KB
Original Source

FormatConditionExpression Class

A format condition used to apply formatting according to the specified expression.

Namespace : DevExpress.DashboardCommon

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

NuGet Package : DevExpress.Dashboard.Core

Declaration

csharp
public class FormatConditionExpression :
    FormatConditionStyleBase,
    IEvaluatorRequired
vb
Public Class FormatConditionExpression
    Inherits FormatConditionStyleBase
    Implements IEvaluatorRequired

Remarks

To create a format condition to apply formatting according to a specified expression, do the following.

Assign the resulting FormatConditionExpression object to the DashboardItemFormatRule.Condition property.

Example

The format rule allows you to create complex conditions for conditional formatting.

This example demonstrates how to create a dashboard parameter in code and pass it to a format rule. The dashboard item is formatted according to the parameter value.

View Example

csharp
using DevExpress.DashboardCommon;

namespace Grid_ExpressionCondition {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            InitializeComponent();
            Dashboard dashboard = new Dashboard(); dashboard.LoadFromXml(@"..\..\Data\Dashboard.xml");
            dashboardViewer1.Dashboard = dashboard;
            GridDashboardItem grid = (GridDashboardItem)dashboard.Items["gridDashboardItem1"];
            GridMeasureColumn extendedPrice = (GridMeasureColumn)grid.Columns[1];
            extendedPrice.Measure.UniqueId = "extendedPrice";

            DashboardParameter priceParameter = new DashboardParameter();
            priceParameter.LookUpSettings = null;
            priceParameter.Name = "priceParameter";
            priceParameter.Type = typeof(decimal);
            priceParameter.Value = 150000;
            priceParameter.Description = "Format values that are greater than";
            dashboard.Parameters.Add(priceParameter);

            GridItemFormatRule greaterThanRule = new GridItemFormatRule(extendedPrice);
            FormatConditionExpression greaterThanCondition = new FormatConditionExpression();
            greaterThanCondition.Expression = "extendedPrice > [Parameters.priceParameter]";
            greaterThanCondition.StyleSettings = 
                new AppearanceSettings(FormatConditionAppearanceType.PaleGreen);
            greaterThanRule.ApplyToRow = true;
            greaterThanRule.Condition = greaterThanCondition;

            grid.FormatRules.AddRange(greaterThanRule);
        }
    }
}
vb
Imports DevExpress.DashboardCommon

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

        Public Sub New()
            InitializeComponent()
            Dim dashboard As New Dashboard()
            dashboard.LoadFromXml("..\..\Data\Dashboard.xml")
            dashboardViewer1.Dashboard = dashboard
            Dim grid As GridDashboardItem =
                CType(dashboard.Items("gridDashboardItem1"), GridDashboardItem)
            Dim extendedPrice As GridMeasureColumn = CType(grid.Columns(1), GridMeasureColumn)
            extendedPrice.Measure.UniqueId = "extendedPrice"

            Dim priceParameter As New DashboardParameter()
            priceParameter.LookUpSettings = Nothing
            priceParameter.Name = "priceParameter"
            priceParameter.Type = GetType(Decimal)
            priceParameter.Value = 150000
            priceParameter.Description = "Format values that are greater than"
            dashboard.Parameters.Add(priceParameter)

            Dim greaterThanRule As New GridItemFormatRule(extendedPrice)
            Dim greaterThanCondition As New FormatConditionExpression()
            greaterThanCondition.Expression = "extendedPrice > [Parameters.priceParameter]"
            greaterThanCondition.StyleSettings =
                New AppearanceSettings(FormatConditionAppearanceType.PaleGreen)
            greaterThanRule.ApplyToRow = True
            greaterThanRule.Condition = greaterThanCondition

            grid.FormatRules.AddRange(greaterThanRule)
        End Sub
    End Class
End Namespace

Inheritance

Object FormatConditionBase FormatConditionStyleBase FormatConditionExpression

See Also

FormatConditionExpression Members

Expression Constants, Operators, and Functions

DevExpress.DashboardCommon Namespace