Version

BeforeMenuPopulate Event

Occurs before the list of menu items has been populated with the default FilterTools.
Syntax
'Declaration
 
Public Event BeforeMenuPopulate As BeforeMenuPopulateEventHandler
public event BeforeMenuPopulateEventHandler BeforeMenuPopulate
Event Data

The event handler receives an argument of type BeforeMenuPopulateEventArgs containing data related to this event. The following BeforeMenuPopulateEventArgs properties provide information specific to this event.

PropertyDescription
ColumnFilter Returns the column filter associated with the current filtering operation.
Handled (Inherited from System.ComponentModel.HandledEventArgs) 
MenuItems Returns the list of tools that will be shown by the filter provider.
Remarks

This event is fired after the UltraGrid's Infragistics.Win.UltraWinGrid.UltraGridBase.BeforeRowFilterDropDown event. While the purpose of the grid's event is to populate the contents of the tree, the purpose of this event, and the corresponding AfterMenuPopulate, is to handle the creation and positioning of the various menu items that appear when the filter provider is shown.

Note: Marking this event as handled will prevent the provider from adding all standard menu tiems, including the tree. Since the FilterTreeTool cannot be manually created, if you would like to reposition this element, the AfterMenuPopulate event should be used instead.

Example
The following code illustrates how to create a simple class that derives from SpecialFilterOperand to allow the filtering of odd or even integers. This class is then used to manually populate the list of items shown by the filter provider.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Imports Infragistics.Win.UltraWinGrid
Imports Infragistics.Win.SupportDialogs.FilterUIProvider

Public Class OddEvenSpecialOperand 
    Inherits SpecialFilterOperand 
    Private isOdd As Boolean 
    
    Public Sub New(ByVal isOdd As Boolean) 
        MyBase.New(If(isOdd, "Odd", "Even")) 
        Me.isOdd = isOdd 
    End Sub 
    
    Public Overloads Overrides Function Match(ByVal comparisonOperator As FilterComparisionOperator, ByVal value As Object) As Boolean 
        If value Is Nothing OrElse value Is DBNull.Value Then 
            Return False 
        End If 
        
        Dim modVal As Integer = CInt(value) Mod 2 
        Return If(isOdd, modVal <> 0, modVal = 0) 
    End Function 
    
    Public Overloads Overrides Function SupportsDataType(ByVal dataType As Type) As Boolean 
        ' We only want to be able to perform this comparison on an integer 
        Dim underlyingType As Type = Infragistics.Win.Utilities.GetUnderlyingType(dataType) 
        Return underlyingType Is GetType(Integer) 
    End Function 
    
    Public Overloads Overrides Function SupportsOperator(ByVal comparisonOperator As FilterComparisionOperator) As Boolean 
        ' It doesn't really make any sense to say that something is "less than" an odd or even number, 
        ' so only allow "Equals" comparisons 
        Return comparisonOperator = FilterComparisionOperator.Equals 
    End Function 
End Class 

Private _evenOperand As OddEvenSpecialOperand 
Public ReadOnly Property EvenOperand() As OddEvenSpecialOperand 
    Get 
        If Me._evenOperand Is Nothing Then 
            Me._evenOperand = New OddEvenSpecialOperand(False) 
        End If 
        
        Return Me._evenOperand 
    End Get 
End Property 

Private _oddOperand As OddEvenSpecialOperand 
Public ReadOnly Property OddOperand() As OddEvenSpecialOperand 
    Get 
        If Me._oddOperand Is Nothing Then 
            Me._oddOperand = New OddEvenSpecialOperand(True) 
        End If 
        
        Return Me._oddOperand 
    End Get 
End Property 

Private Sub ultraGridFilterUIProvider1_BeforeMenuPopulate(ByVal sender As Object, ByVal e As BeforeMenuPopulateEventArgs) 
    ' Mark the event as handled since we will be adding our own items 
    e.Handled = True 
    
    Dim filterConditions As FilterConditionsCollection = e.ColumnFilter.FilterConditions 
    
    ' Add only two operands, "Even" and "Odd". Note that we use cached operands since we 
    ' want to be able to check to see if we've already applied the operand and update the 
    ' checked status accordingly 
    Dim oddTool As New FilterOperandTool("Odd", Me.OddOperand) 
    Dim evenTool As New FilterOperandTool("Even", Me.EvenOperand) 
    
    For i As Integer = 0 To filterConditions.Count - 1 
        Dim condition As FilterCondition = filterConditions(i) 
        If condition.ComparisionOperator = FilterComparisionOperator.Equals Then 
            If condition.CompareValue Is Me.OddOperand Then 
                oddTool.Checked = True 
            ElseIf condition.CompareValue Is Me.EvenOperand Then 
                evenTool.Checked = True 
            End If 
        End If 
    Next 
    
    e.MenuItems.Add(evenTool) 
    e.MenuItems.Add(oddTool) 
End Sub
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win.SupportDialogs.FilterUIProvider;

public class OddEvenSpecialOperand : SpecialFilterOperand
{
    private bool isOdd;

    public OddEvenSpecialOperand(bool isOdd) :
        base(isOdd ? "Odd" : "Even")
    {
        this.isOdd = isOdd;
    }

    public override bool Match(FilterComparisionOperator comparisonOperator, object value)
    {
        if (value == null || value == DBNull.Value)
            return false;

        int modVal = (int)value % 2;
        return isOdd ? modVal != 0 : modVal == 0;
    }

    public override bool SupportsDataType(Type dataType)
    {
        // We only want to be able to perform this comparison on an integer
        Type underlyingType = Infragistics.Win.Utilities.GetUnderlyingType(dataType);
        return underlyingType == typeof(int);
    }

    public override bool SupportsOperator(FilterComparisionOperator comparisonOperator)
    {
        // It doesn't really make any sense to say that something is "less than" an odd or even number,
        // so only allow "Equals" comparisons
        return comparisonOperator == FilterComparisionOperator.Equals;
    }
}

private OddEvenSpecialOperand evenOperand;
public OddEvenSpecialOperand EvenOperand
{
    get
    {
        if (this.evenOperand == null)
            this.evenOperand = new OddEvenSpecialOperand(false);

        return this.evenOperand;
    }
}
       
private OddEvenSpecialOperand oddOperand;
public OddEvenSpecialOperand OddOperand
{
    get
    {
        if (this.oddOperand == null)
            this.oddOperand = new OddEvenSpecialOperand(true);

        return this.oddOperand;
    }
}

private void ultraGridFilterUIProvider1_BeforeMenuPopulate(object sender, BeforeMenuPopulateEventArgs e)
{
    // Mark the event as handled since we will be adding our own items
    e.Handled = true;

    FilterConditionsCollection filterConditions = e.ColumnFilter.FilterConditions;

    // Add only two operands, "Even" and "Odd".  Note that we use cached operands since we 
    // want to be able to check to see if we've already applied the operand and update the
    // checked status accordingly
    FilterOperandTool oddTool = new FilterOperandTool("Odd", this.OddOperand);    
    FilterOperandTool evenTool = new FilterOperandTool("Even", this.EvenOperand);

    for (int i = 0; i < filterConditions.Count; i++)
    {
        FilterCondition condition = filterConditions[i];
        if (condition.ComparisionOperator == FilterComparisionOperator.Equals)
        {
            if (condition.CompareValue == this.OddOperand)
                oddTool.Checked = true;
            else if (condition.CompareValue == this.EvenOperand)
                evenTool.Checked = true;
        }
    }

    e.MenuItems.Add(evenTool);
    e.MenuItems.Add(oddTool);
}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also