Skip to main content

Composite Formatting

  • 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]}
Component Description
index A number starting from 0 that identifies a corresponding item in the list of objects.
alignment A signed integer that indicates the preferred formatted field width. This component is optional. Read the following topic in MSDN for detailed information: Alignment in Composite Formatting.
formatString A 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. Read the following topic in MSDN for detailed information: Format String in Composite Formatting.

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.

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

Format Numbers - WinForms Text Editor, DevExpress

Format Date and Time

Set the FormatType property to FormatType.DateTime.

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

Format Dates - WinForms Text Editor, DevExpress

Format Strings

Set the FormatType property to FormatType.Custom.

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

Format Strings - WinForms Text Editor, 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