Back to Devexpress

FormatInfo.FormatType Property

corelibraries-devexpress-dot-utils-dot-formatinfo.md

latest11.5 KB
Original Source

FormatInfo.FormatType Property

Gets or sets the type of formatting specified by the current FormatInfo object.

Namespace : DevExpress.Utils

Assembly : DevExpress.Data.v25.2.dll

NuGet Package : DevExpress.Data

Declaration

csharp
public virtual FormatType FormatType { get; set; }
vb
Public Overridable Property FormatType As FormatType

Property Value

TypeDescription
FormatType

One of FormatType values specifying the formatting type.

|

Available values:

NameDescription
None

No formatting is performed.

Setting the FormatInfo.FormatType property to None clears the FormatInfo.FormatString property and sets the FormatInfo.Format object to null.

| | Numeric |

Specifies that values should be formatted as numbers.

Setting FormatInfo.FormatType to Numeric assigns the static System.Globalization.NumberFormatInfo.CurrentInfo format provider to the FormatInfo.Format property. This defines the format provider for the current culture.

Also FormatInfo.FormatString is set to an empty string.

| | DateTime |

Specifies that values should be formatted as the DateTime type.

Setting FormatInfo.FormatType to DateTime assigns the static CurrentInfo format provider to the FormatInfo.Format property. This defines the format provider for the current culture. Also FormatInfo.FormatString is set to “d” (short date pattern).

| | Custom |

Use Custom to format string values.

Use Custom when assigning a custom IFormatProvider to the FormatInfo.Format property.

Setting FormatInfo.FormatType to Custom does not change the FormatInfo.Format and FormatInfo.FormatString property values.

|

Remarks

Use the FormatType and FormatInfo.FormatString properties to format values based on the current language and regional settings (culture). FormatType specifies the type of values to be formatted. FormatInfo.FormatString specifies a format pattern appropriate for the current FormatType value. You can refer to the Standard Numeric Format Strings and Date and Time Format Strings topics in MSDN for information on format specifiers.

Note

Changing the FormatType property automatically resets the FormatString property. Thus, it is recommended to set FormatType prior to FormatString.

Setting the FormatType property changes the format provider used when formatting values by the FormatInfo.GetDisplayText function.

Format providers supply information such as the character to use as the decimal point when formatting numeric strings and the separation character to use when formatting a DateTime object. The FormatInfo.Format property specifies the format provider to use.

You can change the FormatInfo.Format property explicitly by assigning a IFormatProvider object. This can be useful if you wish to format values according to a specific culture (not the current one). In this case, you also need to set the FormatType property to FormatType.Custom.

See Formatting Values, to learn more.

Example

The sample code below formats display values of the date and text editors. The FormatInfo.FormatType and FormatInfo.FormatString properties of the editor’s RepositoryItem.DisplayFormat object are used for this purpose.

The image below displays the editors before and after formatting their display values.

csharp
dateEdit1.Properties.DisplayFormat.FormatType = FormatType.DateTime;
dateEdit1.Properties.DisplayFormat.FormatString = "MMMM/yyyy";
textEdit1.Properties.DisplayFormat.FormatType = FormatType.Numeric;
textEdit1.Properties.DisplayFormat.FormatString = "c2";
vb
DateEdit1.Properties.DisplayFormat.FormatType = FormatType.DateTime
DateEdit1.Properties.DisplayFormat.FormatString = "MMMM/yyyy"
TextEdit1.Properties.DisplayFormat.FormatType = FormatType.Numeric
TextEdit1.Properties.DisplayFormat.FormatString = "c2"

The following code snippets (auto-collected from DevExpress Examples) contain references to the FormatType property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-grid-copy-cells-in-biff8-format-using-excel-export-api/CS/gridCopyToClipboardExample/CopyToClipboardHelper.cs#L32

csharp
// Setup number format
if(gridColumn.DisplayFormat.FormatType == FormatType.DateTime)
    column.ApplyFormatting(XlCellFormatting.FromNetFormat(gridColumn.DisplayFormat.FormatString, true));

xaf-win-gantt-control/CS/XPO/GanttSolutionXPO/GanttSolutionXPO.Win/Editors/CustomGanttEditor.cs#L74

csharp
ganttColumn.Format.FormatString = column.DisplayFormat;
ganttColumn.Format.FormatType = DevExpress.Utils.FormatType.Custom;
control.Columns.Add(ganttColumn);

winforms-treelist-unbound-columns/CS/TreeList_UnboundDataViaEvent/Form1.cs#L32

csharp
unbColumnMarchChange.Caption = "Change from Previous Year";
unbColumnMarchChange.Format.FormatType = DevExpress.Utils.FormatType.Numeric;
unbColumnMarchChange.Format.FormatString = "p2";

winforms-lookupedit-bind-to-simple-data-types/CS/LookupEdit-StandardBinding/Form1.cs#L22

csharp
gridControl1.DataSource = Products;
gridView1.Columns["UnitPrice"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
gridView1.Columns["UnitPrice"].DisplayFormat.FormatString = "c2";

winforms-pivotgrid-how-to-display-underlying-data/CS/DrillDownDataSourceExample/Form1.cs#L52

csharp
grid.MainView = gridView1;
gridView1.Columns["OrderDate"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
form.Text = string.Format("Underlying Data - {0} Records", dataSource.RowCount);

winforms-grid-copy-cells-in-biff8-format-using-excel-export-api/VB/gridCopyToClipboardExample/CopyToClipboardHelper.vb#L33

vb
' Setup number format
If gridColumn.DisplayFormat.FormatType = FormatType.DateTime Then
    column.ApplyFormatting(XlCellFormatting.FromNetFormat(gridColumn.DisplayFormat.FormatString, True))

winforms-grid-visualize-master-detail-data/VB/Form1.vb#L58

vb
'Format UnitPrice column values as currency
cardView1.Columns("UnitPrice").DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric
cardView1.Columns("UnitPrice").DisplayFormat.FormatString = "c2"

winforms-treelist-unbound-columns/VB/TreeList_UnboundDataViaEvent/Form1.vb#L27

vb
unbColumnMarchChange.Caption = "Change from Previous Year"
unbColumnMarchChange.Format.FormatType = DevExpress.Utils.FormatType.Numeric
unbColumnMarchChange.Format.FormatString = "p2"

winforms-lookupedit-bind-to-simple-data-types/VB/LookupEdit-StandardBinding/Form1.vb#L24

vb
gridControl1.DataSource = Products
gridView1.Columns("UnitPrice").DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric
gridView1.Columns("UnitPrice").DisplayFormat.FormatString = "c2"

winforms-pivotgrid-how-to-display-underlying-data/VB/DrillDownDataSourceExample/Form1.vb#L50

vb
grid.MainView = gridView1
gridView1.Columns("OrderDate").DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
form.Text = String.Format("Underlying Data - {0} Records", dataSource.RowCount)

See Also

Format

FormatString

GetDisplayText(Object)

Parse()

Formatting Values

FormatInfo Class

FormatInfo Members

DevExpress.Utils Namespace