Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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}";