Skip to main content
A newer version of this page is available. .

XRLabel.TextFormatString Property

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

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v18.2.dll

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"
};

See Also