xtrareports-119473-feature-guide-to-devexpress-reports-use-expressions-expressions-tasks-and-solutions-conditionally-change-a-controls-appearance.md
This document describes how to change the appearance of the report control based on a condition.
Select the report control and click the f-button :
In the invoked Expression Editor enter the expression for the ForeColor property that displays prices greater than 50 in Red:
The result is shown in the following image:
You can specify the expression in code:
tableCell4.ExpressionBindings.Add(
new DevExpress.XtraReports.UI.ExpressionBinding()
{
EventName = "BeforePrint",
PropertyName = "ForeColor",
Expression = "Iif([UnitPrice] >= 50, \'Red\',\'Black\') "
});
tableCell4.ExpressionBindings.Add(New DevExpress.XtraReports.UI.ExpressionBinding() With {
.EventName = "BeforePrint",
.PropertyName = "ForeColor",
.Expression = "Iif([UnitPrice] >= 50, 'Red','Black') "
})
Create a new table report bound to the Products table of the sample Northwind database.
Open the Report Explorer window, and right-click the Styles category to create a new visual style:
Right-click the newly created style and select Edit Styles.
In the invoked Styles Editor you can specify the style appearance settings. Set the ForeColor to Red.
Clone the style to create another style.
Change the ForeColor to Black in the new style and close the editor.
Open the Report Explorer window, and select the table2 report element to which you wish to assign the created styles.
Switch to the Properties window and clear the Style settings for the table2 element.
Clear the Style settings for the table2 child elements - the tableCell3 and tableCell4 elements.
Switch to the Expressions tab. Click the ellipsis button next to the StyleName property in the Appearance section.
In the invoked Expression Editor enter the expression that switches between styles and click Ok to close the editor.
Preview the resulting report.