Back to Devexpress

How to: Add Custom Text to a Formatted String

windowsforms-2146-common-features-formatting-values-how-to-add-custom-text-to-a-formatted-string.md

latest1.7 KB
Original Source

How to: Add Custom Text to a Formatted String

  • Nov 13, 2018

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:

Note

To enable formatted input within editors, use Masks.

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