Back to Devexpress

FormatInfo.FormatString Property

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

latest8.5 KB
Original Source

FormatInfo.FormatString Property

Gets the pattern for formatting values.

Namespace : DevExpress.Utils

Assembly : DevExpress.Data.v25.2.dll

NuGet Package : DevExpress.Data

Declaration

csharp
public virtual string FormatString { get; set; }
vb
Public Overridable Property FormatString As String

Property Value

TypeDescription
String

The string representing the format pattern.

|

Remarks

Use the FormatString property to specify the format pattern for formatting values.

Standard format specifiers for composing the format pattern are described in the Standard Numeric Format Strings and Date and Time Format Strings topics in MSDN.

In addition to the format string, you need to specify the format provider which contains information how to interpret the format string. This can be done by defining one of the following properties:

  1. FormatInfo.FormatType. Use this property if you wish to format values based on the current language and regional settings (culture).

  2. FormatInfo.Format. The property allows you to specify the format provider for a specific culture.

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 FormatString 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#L33

csharp
if(gridColumn.DisplayFormat.FormatType == FormatType.DateTime)
    column.ApplyFormatting(XlCellFormatting.FromNetFormat(gridColumn.DisplayFormat.FormatString, true));
else if(gridColumn.DisplayFormat.FormatType != FormatType.None)

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

csharp
ganttColumn.SortIndex = column.SortIndex;
ganttColumn.Format.FormatString = column.DisplayFormat;
ganttColumn.Format.FormatType = DevExpress.Utils.FormatType.Custom;

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

csharp
unbColumnMarchChange.Format.FormatType = DevExpress.Utils.FormatType.Numeric;
unbColumnMarchChange.Format.FormatString = "p2";
tlBandThisYear.Columns.Add(unbColumnMarchChange);

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

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

winforms-pivot-access-other-cell-value-while-calculating-the-current-cell/CS/WinAppCustomCellValue/Form1.cs#L20

csharp
fieldPercentOfBeverages.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
fieldPercentOfBeverages.CellFormat.FormatString = "P";
pivotGridControl1.Fields.Add(fieldPercentOfBeverages);

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

vb
If gridColumn.DisplayFormat.FormatType = FormatType.DateTime Then
    column.ApplyFormatting(XlCellFormatting.FromNetFormat(gridColumn.DisplayFormat.FormatString, True))
ElseIf gridColumn.DisplayFormat.FormatType <> FormatType.None Then

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

vb
cardView1.Columns("UnitPrice").DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric
    cardView1.Columns("UnitPrice").DisplayFormat.FormatString = "c2"
End Sub

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

vb
unbColumnMarchChange.Format.FormatType = DevExpress.Utils.FormatType.Numeric
unbColumnMarchChange.Format.FormatString = "p2"
tlBandThisYear.Columns.Add(unbColumnMarchChange)

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

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

winforms-pivot-access-other-cell-value-while-calculating-the-current-cell/VB/WinAppCustomCellValue/Form1.vb#L17

vb
fieldPercentOfBeverages.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
fieldPercentOfBeverages.CellFormat.FormatString = "P"
pivotGridControl1.Fields.Add(fieldPercentOfBeverages)

See Also

Format

FormatType

GetDisplayText(Object)

Formatting Values

FormatInfo Class

FormatInfo Members

DevExpress.Utils Namespace