How to: Enter numeric values

  • 3 minutes to read

You can use the CalcEdit and SpinEdit editors to edit numeric values. These editors support masked inputs and provide dedicated UIs (a drop-down calculator and increment/decrement buttons). You can also customize any text editor to accept numeric values in the edit box.

CalcEdit and SpinEdit Controls

The CalcEdit and SpinEdit editors allow you to edit numeric values in various formats (integer and floating-point values, currency and percentage).

CalcEditAndSpinEdit.png

These editors use numeric masks (MaskType.Numeric) to limit the input to valid numbers.

Change the input pattern

You can use the editor's MaskProperties.EditMask (_editor._Properties.Mask.EditMask) setting to change the default input pattern.

The following code formats an editor's values as a percentage with 2 decimal places. See Mask Type: Numeric for information on supported numeric mask specifiers.


calcEdit1.Properties.Mask.EditMask = "P2";
calcEdit1.Properties.Mask.UseMaskAsDisplayFormat = true;

CalcEdit-P2Mask

Storing values

The CalcEdit and SpinEdit controls store their values in the Value property of the Decimal data type. Use the editors' BaseEdit.EditValue property for data binding (the EditValue property is in sync with the Value property). When you bind these editors to a numeric data source field, the editors maintain automatic conversion between the Decimal data type and the bound field's data type.

Text Editors

To allow a text editor (TextEdit or its descendant) to accept numeric values in the edit box, enable the Numeric mask type with the MaskProperties.MaskType (editor.Properties.Mask.MaskType) property, and specify the input pattern with the MaskProperties.EditMask (_editor._Properties.Mask.EditMask) setting. If you do not specify the EditMask setting, the editor uses the default numeric pattern that allows you to enter any decimal numbers.

You can use the AppearanceObject.HAlignment (editor.Properties.Appearance.TextOptions.HAlignment) property to change numeric values' text alignment.


textEdit1.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
textEdit1.Properties.Mask.EditMask = ""; //Use the default pattern for decimal values
textEdit1.Properties.Mask.UseMaskAsDisplayFormat = true;
textEdit1.Properties.Appearance.TextOptions.HAlignment = HorzAlignment.Far;
textEdit1.EditValue = 98536.76m;

TextEdit-NumericMaskType

A bound text editor automatically converts the entered text to the underlying numeric data type (the data type of the bound data source field).

An unbound text editor converts the entered text to the data type that corresponds to the current mask pattern (for example, the Decimal data type corresponds to the "n" mask pattern). To explicitly specify the target data type, initialize the BaseEdit.EditValue property with any value of this data type.

See Also