Back to Devexpress

PivotGridControl.FieldFilterChanging Event

windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotgridcontrol-278bbc8e.md

latest6.7 KB
Original Source

PivotGridControl.FieldFilterChanging Event

Allows you to customize the filter that is being applied or cancel filtering.

Namespace : DevExpress.XtraPivotGrid

Assembly : DevExpress.XtraPivotGrid.v25.2.dll

NuGet Package : DevExpress.Win.PivotGrid

Declaration

csharp
public event PivotFieldFilterChangingEventHandler FieldFilterChanging
vb
Public Event FieldFilterChanging As PivotFieldFilterChangingEventHandler

Event Data

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

PropertyDescription
CancelGets or sets whether to cancel changing the filter condition.
FieldGets the field being processed. Inherited from PivotFieldEventArgsBase<T>.
FilterTypeGets the current filter type.
ShowBlanksGets whether records that contain NULL values in the current field are processed by the control.
ValuesGets the collection of filter values that is about to be assigned to the filter.

Remarks

The FieldFilterChanging event occurs before a field’s filter condition is changed. To obtain the collection of filter values which is about to be assigned to the filter, use the event parameter’s PivotFieldFilterChangingEventArgs.Values property. To cancel changing the current filter values collection, set the PivotFieldFilterChangingEventArgs.Cancel property to true. You can also obtain the field for which the filter condition is being changed, and the current filter type, using the event parameter’s PivotFieldEventArgsBase<T>.Field and PivotFieldFilterChangingEventArgs.FilterType properties, respectively.

After the filter condition has been changed, the PivotGridControl.FieldFilterChanged event is fired.

Note

To remove default filter items and add custom items instead, use the PivotGridControl.CustomFilterPopupItems event.

Example

The following example shows how to prevent end-users from changing the filter condition.In this example, the FieldFilterChanging event is handled to prevent an end-user from hiding the 'Beverages' field value. If an end-user tries to hide the 'Beverages' field value, the event handler sets the event parameter's Cancel property to true to cancel changing the filter condition.

csharp
using System;
using System.Windows.Forms;
using DevExpress.XtraPivotGrid;

namespace EmptyWinApp {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e) {
            this.productReportsTableAdapter.Fill(this.productReports._ProductReports);
        }
        private void pivotGridControl1_FieldFilterChanging(object sender,
                PivotFieldFilterChangingEventArgs e) {
            if(object.ReferenceEquals(e.Field, fieldCategoryName)) {
                if((e.Field.FilterValues.FilterType == PivotFilterType.Excluded && 
                        e.Values.Contains("Beverages")) ||
                    (e.Field.FilterValues.FilterType == PivotFilterType.Included &&
                        !e.Values.Contains("Beverages"))) {
                    MessageBox.Show("You are not allowed to hide the 'Beverages' value.");
                    e.Cancel = true;
                }
            }
        }
    }
}
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraPivotGrid

Namespace EmptyWinApp
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            Me.productReportsTableAdapter.Fill(Me.productReports._ProductReports)
        End Sub
        Private Sub pivotGridControl1_FieldFilterChanging(ByVal sender As Object, _
                                                          ByVal e As PivotFieldFilterChangingEventArgs) _
                                                      Handles pivotGridControl1.FieldFilterChanging
            If Object.ReferenceEquals(e.Field, fieldCategoryName) Then
                If (e.Field.FilterValues.FilterType = PivotFilterType.Excluded _
                    AndAlso e.Values.Contains("Beverages")) _
                OrElse (e.Field.FilterValues.FilterType = PivotFilterType.Included _
                        AndAlso (Not e.Values.Contains("Beverages"))) Then
                    MessageBox.Show("You are not allowed to hide the 'Beverages' value.")
                    e.Cancel = True
                End If
            End If
        End Sub
    End Class
End Namespace

See Also

Values

Cancel

Field

FilterType

FieldFilterChanged

PivotGridControl Class

PivotGridControl Members

DevExpress.XtraPivotGrid Namespace