Back to Devexpress

Composite Formatting

windowsforms-2143-common-features-formatting-values-composite-formatting.md

latest4.0 KB
Original Source

Composite Formatting

  • Apr 14, 2025
  • 2 minutes to read

Composite Formatting allows you to add custom text to the output formatted string.

Format Syntax

A format string takes the following form and consists of the following components:

{index[,alignment][:formatString]}
ComponentDescription
indexA number starting from 0 that identifies a corresponding item in the list of objects.
alignmentA signed integer that indicates the preferred formatted field width. This component is optional.
formatStringA format string that is appropriate for the type of object being formatted. The general (“G”) format specifier for a numeric, date and time, or enumeration type is used if formatString is not specified. The colon is required if formatString is specified.

Use the FormatInfo.FormatType and FormatInfo.FormatString properties to specify the format type and pattern.

Read the following topic for a list of the most common format specifiers for numeric and date/time values: Format Specifiers.

Format Numbers

Set the FormatType property to FormatType.Numeric.

csharp
spinEdit1.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
spinEdit1.Properties.DisplayFormat.FormatString = "{0:c2} / day";
vb
spinEdit1.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric
spinEdit1.Properties.DisplayFormat.FormatString = "{0:c2} / day"

Format Date and Time

Set the FormatType property to FormatType.DateTime.

csharp
dateEdit1.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
dateEdit1.Properties.DisplayFormat.FormatString = "{0:D}";
vb
dateEdit1.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
dateEdit1.Properties.DisplayFormat.FormatString = "{0:D}"

Format Strings

Set the FormatType property to FormatType.Custom.

csharp
textEdit1.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
textEdit1.Properties.DisplayFormat.FormatString = " {0,-15} .NET Developer at DevExpress";
vb
textEdit1.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom
textEdit1.Properties.DisplayFormat.FormatString = " {0,-15} .NET Developer at DevExpress"

Cheat Sheets and Best Practices

DevExpress WinForms UI controls share the same value formatting and masking techniques. Read the following quick-reference guides for detailed information and examples:

See Also

Input Mask

HTML-inspired Text Formatting