Back to Devexpress

PivotGridControl.FieldValueDisplayText Event

windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotgridcontrol-3e6c82e0.md

latest16.6 KB
Original Source

PivotGridControl.FieldValueDisplayText Event

Allows you to change the display text and display field’s data in a more user-friendly format.

Namespace : DevExpress.XtraPivotGrid

Assembly : DevExpress.XtraPivotGrid.v25.2.dll

NuGet Package : DevExpress.Win.PivotGrid

Declaration

csharp
public event PivotFieldDisplayTextEventHandler FieldValueDisplayText
vb
Public Event FieldValueDisplayText As PivotFieldDisplayTextEventHandler

Event Data

The FieldValueDisplayText event's data class is PivotFieldDisplayTextEventArgs. The following properties provide information specific to this event:

PropertyDescription
CustomTotalGets the custom total that corresponds to the currently processed column/row header. Inherited from PivotFieldValueEventArgsBase<T>.
DataThis member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Inherited from PivotFieldValueEventArgs.
DataFieldGets the data field that specifies the processed value. Inherited from PivotFieldValueEventArgsBase<T>.
DisplayTextGets or sets the item’s display text.
FieldGets the field being processed. Inherited from PivotFieldEventArgsBase<T>.
FieldIndexGets the field position among the visible fields within the header area. Inherited from PivotFieldValueEventArgsBase<T>.
IsCollapsedGets whether the processed field value is collapsed. Inherited from PivotFieldValueEventArgsBase<T>.
IsColumnGets whether the field is displayed within the Column Header Area. Inherited from PivotFieldValueEventArgsBase<T>.
IsOthersValueGets or sets whether the current header corresponds to the “Others” row/column. Inherited from PivotFieldValueEventArgsBase<T>.
IsPopulatingFilterDropdownGets whether the current event is called to populate the filter dropdown.
ItemFor internal use. Inherited from PivotFieldValueEventArgsBase<T>.
MaxIndexGets the maximum row index (for row fields) or column index (for column fields) that corresponds to the processed field value. Inherited from PivotFieldValueEventArgsBase<T>.
MinIndexGets the minimum row index (for row fields) or column index (for column fields) that corresponds to the processed field value. Inherited from PivotFieldValueEventArgsBase<T>.
ValueGets the processed item’s value.
ValueTypeGets the type of the currently processed header of a column or a row. Inherited from PivotFieldValueEventArgsBase<T>.

The event data class exposes the following methods:

MethodDescription
ChangeExpandedState()Changes the expanded state of the field value currently being processed. Inherited from PivotFieldValueEventArgsBase<T>.
CreateDrillDownDataSource()Returns data records that are used to calculate a summary value for the specified cell. Inherited from PivotFieldValueEventArgsBase<T>.
CreateDrillDownDataSource(List<String>)Returns data records that are used to calculate a summary value for the specified cell. Inherited from PivotFieldValueEventArgsBase<T>.
CreateDrillDownDataSource(Int32, List<String>)Returns data records used to calculate a summary value for the specified cell in OLAP and server mode. Inherited from PivotFieldValueEventArgsBase<T>.
CreateDrillDownDataSource(Int32)Returns data records that are used to calculate a summary value for the specified cell. Inherited from PivotFieldValueEventArgsBase<T>.
CreateOLAPDrillDownDataSource(Int32, List<String>)Obsolete. In OLAP mode, returns a list of records used to calculate a summary value for the specified cell. Inherited from PivotFieldValueEventArgsBase<T>.
CreateServerModeDrillDownDataSource(Int32, List<String>)Obsolete. In server mode, returns a list of records used to calculate a summary value for the specified cell. Inherited from PivotFieldValueEventArgsBase<T>.
GetCellValue(Int32, Int32)Returns a value displayed in the specified cell. Inherited from PivotFieldValueEventArgsBase<T>.
GetFieldValue(T, Int32)Returns the specified column or row field value for the cell, addressed by its zero-based index in the Data Area. Inherited from PivotFieldValueEventArgsBase<T>.
GetHigherLevelFields()Returns the parent field for the field value currently being processed. Inherited from PivotFieldValueEventArgsBase<T>.
GetHigherLevelFieldValue(T)Returns the value of a specific parent field corresponding to the field value currently being processed. Inherited from PivotFieldValueEventArgsBase<T>.

Remarks

Check the Display Text Event option in the following demo:

Run Demo: XtraPivotGrid MainDemo — Calculated Fields

Do not call the e.CreateDrillDownDataSource method in the FieldValueDisplayText handler. It can return null in certain cases (sorting, filter popup) or cause other issues.

The following table illustrates event data supplied for different visual elements that trigger the FieldValueDisplayText event.

Visual Element (Event Source)e.Field valuee.IsPopulatingFilterDropdown value
Field value or Total HeaderColumn field or Row fieldfalse
Data Field HeaderData fieldfalse
Grand Total HeaderNullfalse
Item within a filter dropdownColumn, row or filter field whose dropdown is invokedtrue

To specify a text to display, assign a string to the PivotFieldDisplayTextEventArgs.DisplayText property. You can use HTML formatting, as illustrated in the HTML in Field Values live example available in our demo center.

To display field values instead of automatically created and formatted strings, use the following code:

csharp
e.DisplayText = e.Value?.ToString()
vb
e.DisplayText = If(e.Value Is Nothing, Nothing, e.Value.ToString())

Use the PivotGridControl.CustomCellDisplayText event or PivotGridFieldBase.CellFormat property to customize the display text of cells in the Data area.

Important

Do not change cell values, modify the control’s layout, or change the control’s object model in the events used for custom control painting. Actions that update the layout can cause the control to malfunction.

Example

The PivotGridControl.FieldValueDisplayText event allows you to customize field value texts for grand totals.

To do this, check the field value type using the PivotFieldValueEventArgsBase<T>.ValueType event parameter and provide the required display texts using PivotFieldDisplayTextEventArgs.DisplayText.

csharp
private void pivotGridControl1_FieldValueDisplayText(object sender, DevExpress.XtraPivotGrid.PivotFieldDisplayTextEventArgs e) {
    if (e.ValueType == DevExpress.XtraPivotGrid.PivotGridValueType.GrandTotal) {
        if (e.IsColumn)
            e.DisplayText = "*Custom Column Grand Total*";
        else
            e.DisplayText = "*Custom Row Grand Total*";
    }
}
vb
Private Sub pivotGridControl1_FieldValueDisplayText(ByVal sender As Object, ByVal e As DevExpress.XtraPivotGrid.PivotFieldDisplayTextEventArgs)
    If e.ValueType = DevExpress.XtraPivotGrid.PivotGridValueType.GrandTotal Then
        If e.IsColumn Then
            e.DisplayText = "*Custom Column Grand Total*"
        Else
            e.DisplayText = "*Custom Row Grand Total*"
        End If
    End If
End Sub

More Examples

View Example: How to Hide Empty Field Values (Columns/Rows)

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FieldValueDisplayText event.

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-pivotgrid--display-the-difference-of-income-and-outlay-in-totals/CS/PivotGridCustomSummaryExample/Form1.cs#L13

csharp
SelectCustomSummaryApproach(pivotGridControl1.OptionsData.DataProcessingEngine);
pivotGridControl1.FieldValueDisplayText += PivotGridControl1_FieldValueDisplayText;
pivotGridControl1.DataSource = TestData.GetData();

winforms-pivotgrid--display-the-difference-of-income-and-outlay-in-totals/VB/PivotGridCustomSummaryExample/Form1.vb#L12

vb
SelectCustomSummaryApproach(pivotGridControl1.OptionsData.DataProcessingEngine)
AddHandler pivotGridControl1.FieldValueDisplayText, AddressOf PivotGridControl1_FieldValueDisplayText
pivotGridControl1.DataSource = TestData.GetData()

See Also

CustomCellDisplayText

ValueFormat

PivotGridControl Class

PivotGridControl Members

DevExpress.XtraPivotGrid Namespace