GridItemFormatRule Class
A format rule used to apply conditional formatting to the Grid dashboard item.
Namespace: DevExpress.DashboardCommon
Assembly: DevExpress.Dashboard.v24.1.Core.dll
NuGet Package: DevExpress.Dashboard.Core
Declaration
Remarks
The Grid dashboard item allows you to apply conditional formatting to cells. The GridDashboardItem.FormatRules property provides access to a collection of the GridItemFormatRule objects that are used to define formatting settings.
To add a new format rule, create the GridItemFormatRule object and specify the following settings.
- Create a required condition (the FormatConditionBase descendant), specify its settings and assign the resulting object to the DashboardItemFormatRule.Condition property.
- Set a measure/dimension whose values are checked using the specified condition by specifying the CellsItemFormatRule.DataItem property. The CellsItemFormatRule.DataItemApplyTo property specifies the measure/dimension to whose values a formatting should be applied.
- Optionally, enable the CellsItemFormatRule.ApplyToRow flag to apply formatting to the entire grid row.
Finally, add the created format rule to the GridDashboardItem.FormatRules collection. You can use the DashboardItemFormatRule.Enabled property to specify whether the current format rule is enabled.
Example
The Value format condition (FormatConditionValue) allows you to compare dimension/measure values with predefined static values.
This example demonstrates how to apply conditional formatting to Grid cells whose values are greater than, less than or between the specified values.
using DevExpress.DashboardCommon;
using DevExpress.XtraEditors;
namespace Grid_FormatRules {
public partial class ValueConditionForm : XtraForm {
public ValueConditionForm() {
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];
GridItemFormatRule lessThanRule = new GridItemFormatRule(extendedPrice);
FormatConditionValue lessThanCondition = new FormatConditionValue();
lessThanCondition.Condition = DashboardFormatCondition.LessOrEqual;
lessThanCondition.Value1 = 100000;
lessThanCondition.StyleSettings =
new AppearanceSettings(FormatConditionAppearanceType.FontRed);
lessThanRule.Condition = lessThanCondition;
GridItemFormatRule betweenRule = new GridItemFormatRule(extendedPrice);
FormatConditionValue betweenCondition = new FormatConditionValue();
betweenCondition.Condition = DashboardFormatCondition.Between;
betweenCondition.Value1 = 100000;
betweenCondition.Value2 = 200000;
betweenCondition.StyleSettings =
new AppearanceSettings(FormatConditionAppearanceType.FontYellow);
betweenRule.Condition = betweenCondition;
GridItemFormatRule greaterThanRule = new GridItemFormatRule(extendedPrice);
FormatConditionValue greaterThanCondition = new FormatConditionValue();
greaterThanCondition.Condition = DashboardFormatCondition.GreaterOrEqual;
greaterThanCondition.Value1 = 200000;
greaterThanCondition.StyleSettings =
new AppearanceSettings(FormatConditionAppearanceType.FontGreen);
greaterThanRule.Condition = greaterThanCondition;
grid.FormatRules.AddRange(lessThanRule, betweenRule, greaterThanRule);
}
}
}