Back to Devexpress

PivotGridControl.CustomFilterPopupItems Event

windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotgridcontrol-0150baac.md

latest10.2 KB
Original Source

PivotGridControl.CustomFilterPopupItems Event

Allows you to customize items displayed in the Classic filter popup.

Namespace : DevExpress.XtraPivotGrid

Assembly : DevExpress.XtraPivotGrid.v25.2.dll

NuGet Package : DevExpress.Win.PivotGrid

Declaration

csharp
public event PivotCustomFilterPopupItemsEventHandler CustomFilterPopupItems
vb
Public Event CustomFilterPopupItems As PivotCustomFilterPopupItemsEventHandler

Event Data

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

PropertyDescription
FieldGets the field for which the event has been raised.
ItemsGets the collection of filter items.
ShowBlanksItemGets the ‘Show Blanks’ filter item.

The event data class exposes the following methods:

MethodDescription
CheckAllItems(Boolean)Checks or unchecks all filter items in the PivotCustomFilterPopupItemsEventArgs.Items collection.

Remarks

The CustomFilterPopupItems event is raised when an end-user invokes the filter drop-down list. The event parameter’s PivotCustomFilterPopupItemsEventArgs.Items property returns a collection of filter items. Elements of the collection are represented by the PivotGridFilterItem objects. Initially, the filter items collection contains items representing the unique values stored in the underlying data source in the current field. To hide particular items from the filter drop-down, remove them from the collection.

You can also specify the check state of filter items using their PivotGridFilterItem.IsChecked property. The event parameter provides the PivotCustomFilterPopupItemsEventArgs.CheckAllItems method, which allows you to specify the check state of all filter items in the collection.

To obtain the field for which the filter drop-down is being populated, use the event parameter’s PivotCustomFilterPopupItemsEventArgs.Field property.

The filter drop-down list contains the ‘Show Blanks’ item used to control whether the data records that contain null values in the respective field are processed by the PivotGridControl. To access the ‘Show Blanks’ filter item, use the PivotCustomFilterPopupItemsEventArgs.ShowBlanksItem property.

Note

In the OLAP mode, the PivotCustomFilterPopupItemsEventArgs.ShowBlanksItem property returns null.

Example

The following example shows how to hide filter items whose corresponding field values are not displayed.In this example, the Row Header Area of the PivotGrid contains two fields: 'Category Name' and 'Product Name'. If an end-user hides a particular product category via the 'Category Name' field's filter drop-down, the corresponding products will be excluded from the filter drop-down of the 'Product Name' field. To hide filter items, the CustomFilterPopupItems event is handled.

csharp
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace EmptyWinApp {
    static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
csharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraPivotGrid;
using DevExpress.XtraPivotGrid.Data;

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_CustomFilterPopupItems(object sender, 
                                                        PivotCustomFilterPopupItemsEventArgs e) {

            // Fetches and sorts visible values of the current field.
            List<object> values = e.Field.GetVisibleValues();
            values.Sort();

            // Checks whether the filter drop-down customization logic differs
            // depending on the currently selected filter type.
            // If so, the filter type decides which filter items
            // will be hidden.
            bool? removingCriteria;
            if (((PivotGridControl)sender).OptionsFilterPopup.AllowFilterTypeChanging == false)
                removingCriteria = true;
            else
                removingCriteria = e.Field.FilterValues.FilterType != PivotFilterType.Excluded;

            // Hides filter items that are not currently visible
            // due to the filtering applied.
            for(int i = e.Items.Count - 1; i >= 0; i--) {
                if (e.Items[i].IsChecked == removingCriteria && 
                                values.BinarySearch(e.Items[i].Value) < 0)
                    e.Items.RemoveAt(i);                
            }
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraPivotGrid
Imports DevExpress.XtraPivotGrid.Data

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_CustomFilterPopupItems(ByVal sender As Object, _
                        ByVal e As PivotCustomFilterPopupItemsEventArgs) _
                        Handles pivotGridControl1.CustomFilterPopupItems

            ' Fetches and sorts visible values of the current field.
            Dim values As List(Of Object) = e.Field.GetVisibleValues()
            values.Sort()

            ' Checks whether the filter drop-down customization logic differs
            ' depending on the currently selected filter type.
            ' If so, the filter type decides which filter items
            ' will be hidden.
            Dim removingCriteria As Nullable(Of Boolean)
            If (CType(sender, PivotGridControl)).OptionsFilterPopup.AllowFilterTypeChanging = False Then
                removingCriteria = True
            Else
                removingCriteria = e.Field.FilterValues.FilterType <> PivotFilterType.Excluded
            End If

            ' Hides filter items that are not currently visible
            ' due to the filtering applied.
            For i As Integer = e.Items.Count - 1 To 0 Step -1
                If e.Items(i).IsChecked.Equals(removingCriteria) AndAlso _
                        values.BinarySearch(e.Items(i).Value) < 0 Then
                    e.Items.RemoveAt(i)
                End If
            Next i
        End Sub
    End Class
End Namespace
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms

Namespace EmptyWinApp
    Friend NotInheritable Class Program
        ''' <summary>
        ''' The main entry point for the application.
        ''' </summary>
        Private Sub New()
        End Sub
        <STAThread> _
        Shared Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
            Application.Run(New Form1())
        End Sub
    End Class
End Namespace

See Also

Items

IsChecked

CheckAllItems(Boolean)

Field

ShowBlanksItem

PivotGridControl Class

PivotGridControl Members

DevExpress.XtraPivotGrid Namespace