Skip to main content

XRLabel.TextFormatString Property

Specifies the output format for a value bound to the label.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

[Browsable(true)]
public override string TextFormatString { get; set; }

Property Value

Type Description
String

The output format for a value bound to the label.

Remarks

The TextFormatString property allows you to specify an output format for values bound to the XRLabel‘s Text property.

Note

Ensure the specified format string fits the type of the bound value. For instance, in the code example below the expression Phone: {0:(###)-##-##} expects the phone field to be an integer. This expression does not work for other types, for example for strings. Refer to the following article for more details on formatting: Format types in .NET.

Example

The following code example shows how to specify the TextFormatString property for the XRLabel control.

Note

Refer to the following help topic for information on how to format data at design time: Format Data.

using DevExpress.XtraReports.UI;
using DevExpress.DataAccess.Json;
// ...
string json = "{\"users\":[{\"name\":\"John\",\"phone\":3335588},{\"name\":\"Ann\",\"phone\":4445577}]}";

// Create a label.
XRLabel label = new XRLabel() {
    WidthF = 120,
    // Specify an expression for the label's "Text" property.
    ExpressionBindings = { new ExpressionBinding("BeforePrint", "Text", "[phone]") },
    // Specify a format string for the label's text.
    TextFormatString = "Phone: {0:(###)-##-##}"
};

// Create a report with the label.
XtraReport report = new XtraReport() {
    Bands = {
        new DetailBand() {
            HeightF = 25,
            Controls = {label}
        }
    },
    DataSource = new JsonDataSource() {
        JsonSource = new CustomJsonSource(json)
    },
    DataMember = "users"
};

The following code snippets (auto-collected from DevExpress Examples) contain references to the TextFormatString property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also