Back to Devexpress

PivotCustomFilterPopupItemsEventArgs.Items Property

windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotcustomfilterpopupitemseventargs-f5366770.md

latest5.2 KB
Original Source

PivotCustomFilterPopupItemsEventArgs.Items Property

Gets the collection of filter items.

Namespace : DevExpress.XtraPivotGrid

Assembly : DevExpress.XtraPivotGrid.v25.2.dll

NuGet Package : DevExpress.Win.PivotGrid

Declaration

csharp
public IList<PivotGridFilterItem> Items { get; }
vb
Public ReadOnly Property Items As IList(Of PivotGridFilterItem)

Property Value

TypeDescription
IList<PivotGridFilterItem>

A list of PivotGridFilterItem objects that represent the filter items.

|

Remarks

Initially, the Items collection contains items representing the unique values stored in the underlying data source in the current field. To hide individual items from the filter dropdown, remove the respective elements from the Items collection.

To obtain the field for which the event has been raised, use the PivotCustomFilterPopupItemsEventArgs.Field property.

Example

The following example shows how to add and remove items from the filter dropdown list.In this example, the 'Beverages' item is hidden from the filter dropdown list of the Category field, and a dummy item is created and added to the list. To do this, the CustomFilterPopupItems event is handled. In the event handler, the 'Beverages' item is removed from the event parameter's Items collection, and a new item ('Dummy Item') is added to the collection.

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);
        }
        readonly object dummyItem = new object();
        private void pivotGridControl1_CustomFilterPopupItems(object sender,
                                            PivotCustomFilterPopupItemsEventArgs e) {
            if(object.ReferenceEquals(e.Field, fieldCategoryName)) {
                for(int i = e.Items.Count - 1; i >= 0; i--) {
                    if(object.Equals(e.Items[i].Value, "Beverages")) {
                        e.Items.RemoveAt(i);
                        break;
                    }
                }
                e.Items.Insert(0, new PivotGridFilterItem(dummyItem,
                                                          "Dummy Item",
                                                          e.Field.FilterValues.Contains(dummyItem)));
            }
        }
    }
}
vb
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 ReadOnly dummyItem As New Object()
        Private Sub pivotGridControl1_CustomFilterPopupItems(ByVal sender As Object, ByVal e As PivotCustomFilterPopupItemsEventArgs) Handles pivotGridControl1.CustomFilterPopupItems
            If Object.ReferenceEquals(e.Field, fieldCategoryName) Then
                For i As Integer = e.Items.Count - 1 To 0 Step -1
                    If Object.Equals(e.Items(i).Value, "Beverages") Then
                        e.Items.RemoveAt(i)
                        Exit For
                    End If
                Next i
                e.Items.Insert(0, New PivotGridFilterItem(dummyItem, "Dummy Item", e.Field.FilterValues.Contains(dummyItem)))
            End If
        End Sub
    End Class
End Namespace

See Also

Field

PivotCustomFilterPopupItemsEventArgs Class

PivotCustomFilterPopupItemsEventArgs Members

DevExpress.XtraPivotGrid Namespace