Skip to main content

Members that Support the Formatting Mechanism

  • 3 minutes to read

Format Settings

DevExpress controls that support the formatting mechanism contain properties of the FormatInfo class, which specify the settings used to format different control elements. The FormatInfo class declares two properties that are available at design time: FormatInfo.FormatType and FormatInfo.FormatString.

The FormatInfo.FormatType property has to be set to an appropriate value that identifies the type of the values that need to be formatted.

FormatInfo.FormatType value

Description

FormatType.Numeric

Specifies that numeric values have to be formatted.

FormatType.DateTime

Specifies that date/time values have to be formatted.

FormatType.None

No formatting should be applied.

FormatType.Custom

Specifies that:

The FormatInfo.FormatString property needs to be set to a format specifier or format string that consists of the format specifiers. This will specify the pattern according to which values should be formatted.

There is a set of predefined format specifiers to format numeric and date/time values. The output produced depends upon the regional settings of an end-user’s computer. However, these specifiers allow you to format values according to the predefined formats (for instance, a date/time value can be formatted in the Short Date, Long Date or Full Date/Time form as defined in the system).

If you need greater control over formatting, you need to use custom format strings. Such format strings allow you to construct your own formatting patterns, add custom text to formatted values, specify different formats for positive and negative numeric values, etc. However, when using custom format strings, you cannot always format values so that they are correctly displayed with respect to the user’s regional options. In this case, it is best to construct the format string at runtime so that regional settings can be taken into account. The Thread.CurrentThread.CurrentCulture property can be used to do this.

Note

Set the FormatInfo.FormatString only after changing the FormatInfo.FormatType property. Otherwise, your format string will be lost.

See the Format Specifiers topic for information on the available format specifiers.

Properties Exposed by the DevExpress Controls

The following table lists the properties of the FormatInfo type that are exposed by DevExpress WinForms controls.

DevExpress Control

Format Property

Grid Control

GridColumn.DisplayFormat - formats column values.

DevExpress Editors Library

RepositoryItem.DisplayFormat - formats values within unfocused editors;

RepositoryItem.EditFormat - formats values within focused editors.

To allow end-users to enter text within editors according to specific patterns, use masks. Masks can also be used to format values even in display mode (when an editor is not active).

Tree List Control

TreeListColumn.Format - formats column values.

DevExpress Vertical Grid

RowProperties.Format - formats row values.

XtraPivotGrid

PivotGridFieldBase.CellFormat - formats values within the Data Area;

PivotGridFieldBase.ValueFormat - formats values within the Column Header Area and Row Header Area;

PivotGridFieldBase.TotalCellFormat - formats totals;

PivotGridFieldBase.GrandTotalCellFormat - formats grand totals.