How to: Add Custom Text to a Formatted String

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.



To enable formatted input within editors, use Masks.

textEdit1.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
textEdit1.Properties.DisplayFormat.FormatString = "ID: {0:d4}";