Back to Devexpress

XRLabel.TextFormatString Property

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xrlabel-e30c8d6e.md

latest6.0 KB
Original Source

XRLabel.TextFormatString Property

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

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
[Browsable(true)]
public override string TextFormatString { get; set; }
vb
<Browsable(True)>
Public Overrides Property TextFormatString As String

Property Value

TypeDescription
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.

csharp
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"
};
vb
Imports DevExpress.XtraReports.UI
Imports DevExpress.DataAccess.Json
' ...
Dim json As String = "{""users"":[{""name"":""John"",""phone"":3335588},{""name"":""Ann"",""phone"":4445577}]}"

' Create a label.
Dim label As New XRLabel() With {
.WidthF = 120,
.TextFormatString = "Phone: {0:(###)-##-##}"}
label.ExpressionBindings.Add(New ExpressionBinding("BeforePrint", "Text", "[phone]"))

' Create a report with the label.
Dim report = New XtraReport()
Dim band = New DetailBand() With {.HeightF = 25}
band.Controls.Add(label)
report.DataSource = New JsonDataSource() With {.JsonSource = New CustomJsonSource(json)}
report.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.

reporting-web-forms-object-data-source-constructor-parameters/CS/DXWebApplication1/Default.aspx.cs#L80

csharp
new DevExpress.XtraReports.UI.ExpressionBinding("Text", "?" + parameterName));
paramValueLbl.TextFormatString = "Parameter value: {0}";
pageHeader.Controls.Add(paramValueLbl);

reporting-winforms-use-a-custom-function-in-query-expression/VB/SelectQueryWindowsFormsApplication/Form1.vb#L46

vb
labelCategory.ExpressionBindings.Add(New DevExpress.XtraReports.UI.ExpressionBinding("BeforePrint", "Text", "[CategoryID]"))
labelCategory.TextFormatString = "Category ID: {0}"

reporting-web-forms-object-data-source-constructor-parameters/VB/DXWebApplication1/DXWebApplication1/Default.aspx.vb#L42

vb
paramValueLbl.ExpressionBindings.Add(New ExpressionBinding("Text", "?" + parameterName))
paramValueLbl.TextFormatString = "Parameter value:{0}"
pageHeader.Controls.Add(paramValueLbl)

See Also

Data Binding Modes

XRLabel Class

XRLabel Members

DevExpress.XtraReports.UI Namespace