FormatInfo.Format Property

Gets or sets the IFormatProvider object which specifies how values should be formatted.

Namespace: DevExpress.Utils

Assembly: DevExpress.Data.v20.1.dll

Declaration

[Browsable(false)]
[DefaultValue(null)]
public virtual IFormatProvider Format { get; set; }
<Browsable(False)>
<DefaultValue(Nothing)>
Public Overridable Property Format As IFormatProvider

Property Value

Type Default Description
IFormatProvider

null

The IFormatProvider object which specifies how values should be formatted.

Remarks

The Format property refers to the format provider which contains information on how values should be formatted according to the FormatInfo.FormatString pattern by the FormatInfo.GetDisplayText function. Format providers supply information such as the character to use as the decimal point when formatting numeric strings, or the separation character to use when formatting a DateTime object. Format providers define the characters used for formatting by the format specifiers, but do not define the specifiers themselves.

There are two ways to specify the format provider to use:

  • by setting the FormatInfo.FormatType property. This enables you to format numeric and date/time values according to the current language and regional settings. Setting FormatInfo.FormatType to FormatType.DateTime assigns the static CurrentInfo object to Format. For the FormatType.Numeric value, Format will return the static CurrentInfo object.

    If your application creates several threads which use different language or regional settings (cultures), then you should set the FormatInfo.AlwaysUseThreadFormat property to true. This ensures that the value of the Format property is determined based on the current thread culture each time the property is accessed. Thus when FormatInfo.GetDisplayText is called, the function reads the Format property and formats a value based on its settings, i.e. using the current thread culture.

  • by setting the Format property to an object implementing the IFormatProvider interface explicitly. This can be useful if you want to format values according to a specific culture (not the current one). To use a custom format provider, you need to set the FormatInfo.FormatType property to FormatType.Custom.

Examples

The following example shows the use of the FormatInfo.Format property.

We assign a specific format provider to the FormatInfo.Format property for a date editor and this makes the control to represent date/time values based on settings of this format provider.

The following screenshot shows the date editor after executing this code.

FormatInfo_Format_example

    FormatInfo fInfo = dateEdit1.Properties.DisplayFormat;
    fInfo.FormatType = FormatType.Custom;
    fInfo.FormatString = "D";
    fInfo.Format = CultureInfo.CreateSpecificCulture("fr").DateTimeFormat;
See Also