Skip to main content

How to: Add Custom Text to a Formatted String

The following example demonstrates a way to format numeric values and insert 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.

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

composite_formatting_ex

Note

To enable formatted input within editors, use Masks.

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