Back to Devexpress

Data Formatting

windowsforms-1813-controls-and-libraries-pivot-grid-data-shaping-data-formatting.md

latest3.7 KB
Original Source

Data Formatting

  • Sep 09, 2022
  • 2 minutes to read

PivotGridControl uses a standard formatting mechanism to format displayed values. Refer to Formatting Values for more information on DevExpress WinForms data-aware controls.

The PivotGridControl formats values using the culture specified in the application by default. For instance, the images below demonstrate the same Pivot Grid whose date-time and summary values are formatted as “en-US” or “de-DE”.

en-US culture

de-DE culture

You can change default formatting settings for data cells, field values, totals and grand totals using the following properties:

MemberDescription
PivotGridFieldBase.CellFormatProvides access to the format settings applied to cells.
PivotGridFieldBase.GrandTotalCellFormatProvides access to the format settings applied to grand total values.
PivotGridFieldBase.TotalCellFormatProvides access to the format settings applied to total cells.
PivotGridFieldBase.TotalValueFormatProvides access to the format settings applied to the total header.
PivotGridFieldBase.ValueFormatProvides access to the format settings applied to field values.

Example

The following example shows how to format OrderDate field values and summaries corresponding to the Extended Price field. OrderDate field values are formatted using a long date pattern while Extended Price summaries are formatted as integer currency values.

Refer to the Standard Numeric Format Strings topic for detailed information about the standard numeric format specifiers.

The result of the code is shown below:

csharp
// Formats the OrderDate field's values using a long date pattern.
fieldOrderDate.ValueFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
fieldOrderDate.ValueFormat.FormatString = "D";

// Formats the ExtendedPrice field's values as integer currency values.
fieldExtendedPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
fieldExtendedPrice.CellFormat.FormatString = "c0";
vb
' Formats the OrderDate field's values using a long date pattern.
fieldOrderDate.ValueFormat.FormatType = DevExpress.Utils.FormatType.DateTime
fieldOrderDate.ValueFormat.FormatString = "D"

' Formats the ExtendedPrice field's values as integer currency values.
fieldExtendedPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
fieldExtendedPrice.CellFormat.FormatString = "c0"