Back to Devexpress

Formatting Class

xtrareports-devexpress-dot-xtrareports-dot-ui-92c3e9e8.md

latest5.5 KB
Original Source

Formatting Class

A container of values, which are applied to a control when its owner Formatting Rule‘s condition is true.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public class Formatting :
    XRControlStyle
vb
Public Class Formatting
    Inherits XRControlStyle

The following members return Formatting objects:

Remarks

The formatting which is defined by the current formatting rule is specified by its FormattingRule.Formatting property. The Formatting object, which is returned by this property, contains a set of appearance options (e.g. BackColor , ForeColor , Font , etc.), as well as the Formatting.Visible property, that can be used to conditionally suppress report elements.

Note

If any of the Formatting object’s properties is not set, the corresponding property of a control isn’t changed when this formatting rule is applied.

For more information on using this property, refer to Conditionally Changing a Control’s Appearance.

Note

Formatting rules are only available in the legacy binding mode (when the UserDesignerOptions.DataBindingMode is set to DataBindingMode.Bindings). See Shape Report Data to learn about the recommended approach to shaping report data.

Example

This example demonstrates how to conditionally change a control’s appearance at runtime. For this, it is necessary to create an instance of the FormattingRule class, specify its FormattingRule.Condition and FormattingRule.Formatting properties and add this object to a report’s sheet of formatting rules (XtraReport.FormattingRuleSheet) and to the collection of formatting rules of a control or a band, to which it should be applied (XRControl.FormattingRules). Note that the same task can be also solved at design time, as described in the Conditionally Changing a Control’s Appearance topic.

csharp
using System.Drawing;
using System.Drawing.Printing;
using DevExpress.XtraReports.UI;
// ...

private void XtraReport1_BeforePrint(object sender, CancelEventArgs e) {
    // Create a new rule and add it to a report.
    FormattingRule rule = new FormattingRule();
    this.FormattingRuleSheet.Add(rule);

    // Specify the rule's properties.
    rule.DataSource = this.DataSource;
    rule.DataMember = this.DataMember;
    rule.Condition = "[UnitPrice] >= 30";
    rule.Formatting.BackColor = Color.WhiteSmoke;
    rule.Formatting.ForeColor = Color.IndianRed;
    rule.Formatting.Font = new Font("Arial", 10, FontStyle.Bold);

    // Apply this rule to the detail band.
    this.Detail.FormattingRules.Add(rule);
}
vb
Imports System.Drawing
Imports System.Drawing.Printing
Imports DevExpress.XtraReports.UI
' ...

Private Sub XtraReport1_BeforePrint(ByVal sender As Object, ByVal e As CancelEventArgs) _
Handles MyBase.BeforePrint
    ' Create a new rule and add it to a report.
    Dim rule As New FormattingRule()
    Me.FormattingRuleSheet.Add(rule)

    ' Specify the rule's properties.
    rule.DataSource = Me.DataSource
    rule.DataMember = Me.DataMember
    rule.Condition = "[UnitPrice] >= 30"
    rule.Formatting.BackColor = Color.WhiteSmoke
    rule.Formatting.ForeColor = Color.IndianRed
    rule.Formatting.Font = New Font("Arial", 10, FontStyle.Bold)

    ' Apply this rule to the detail band.
    Me.Detail.FormattingRules.Add(rule)
End Sub

Inheritance

Object BrickStyle XRControlStyle Formatting

See Also

Formatting Members

Conditionally Change the Control's Appearance

DevExpress.XtraReports.UI Namespace