Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Expand]Controls and Libraries
 [Collapse]Common Features
  [Expand]Data Binding Common Concepts
  [Expand]Data Source Wizard
  [Expand]Expressions
  [Expand]Behaviors
  [Expand]Application Appearance
  [Expand]Filtering UI Context
  [Expand]High DPI Support
  [Expand]Scaffolding Wizard
  [Collapse]Formatting Values
    How to: Format Date-Time Values Using the LongDate Pattern
    How to: Format Date-Time Values Using a Custom Format Pattern
    How to: Format a Numeric Value according to its Sign
    How to: Add Custom Text to a Formatted String
    How to: Create a Custom Formatter to Change the Case of String Values
    How to: Create a Custom Formatter to Represent Decimal Values in Binary
    Formatting Approaches
    Members that Support the Formatting Mechanism
    Format Specifiers
    Composite Formatting
    Custom Formatting
   HTML Text Formatting
  [Expand]Menus
  [Expand]Tooltip Management
  [Expand]Saving and Restoring Layouts
   Clipboard - Copy and Paste Operations. Data Formatting
   Version Compatibility: Default Property Values
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Composite Formatting

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

If numeric values need to be formatted, set the FormatInfo.FormatType property to FormatType.Numeric. To format date/time values, set this property to FormatType.DateTime. To format string values, set this property to FormatType.Custom. Then use the FormatInfo.FormatString property to specify a format pattern.

A format pattern can contain any custom text. To insert a formatted value at any position within this text use the "{0}" placeholder. The complete syntax to define the position of the formatted value is as follows (it is described in the Composite Formatting topic in MSDN):

{0[,alignment][:formatString]}

Below is a quote from the Composite Formatting topic in MSDN that describes this syntax:

"The optional alignment component is a signed integer indicating the preferred formatted field width. If the value of alignment is less than the length of the formatted string, alignment is ignored and the length of the formatted string is used as the field width. The formatted data in the field is right-aligned if alignment is positive, and left-aligned if alignment is negative. If padding is necessary, white space is used. The comma is required if alignment is specified."

"The optional formatString component consists of standard or custom format specifiers. If formatString is not specified, the general ("G") format specifier is used. The colon is required if formatString is specified." See the Format Specifiers topic for a list of the most used specifiers used to format numeric and date/time values.

You can refer to MSDN for more details on the Composite Formatting feature.

Expanded Example

The following example demonstrates a way of formatting numeric values and inserting custom display text within the output formatted string.

Assume that a text editor displays numeric identifiers. An identifier should be represented as a four digit field (preceding zeros might be added if necessary); in addition, the "ID:" string needs to be displayed before the formatted identifier. To format values, use the editor's RepositoryItem.DisplayFormat property. The FormatInfo.FormatType property is set to FormatType.Numeric and the FormatInfo.FormatString property is set to an appropriate format pattern.

See the Composite Formatting topic for more details on this formatting type.

For an editor whose BaseEdit.EditValue property is set to 5, the display text will be as follows.

Note

To enable formatted input within editors, use Masks.

How would you rate this topic?​​​​​​​