バージョン

BeforeMenuPopulate イベント

メニュー項目のリストがデフォルトの FilterTool で作成される前に発生します。
シンタックス
'宣言
 
Public Event BeforeMenuPopulate As BeforeMenuPopulateEventHandler
public event BeforeMenuPopulateEventHandler BeforeMenuPopulate
イベント データ

イベント ハンドラが、このイベントに関連するデータを含む、BeforeMenuPopulateEventArgs 型の引数を受け取りました。次の BeforeMenuPopulateEventArgs プロパティには、このイベントの固有の情報が記載されます。

プロパティ解説
ColumnFilter 現在のフィルター操作と関連付けられた列フィルターを返します。
Handled System.ComponentModel.HandledEventArgsから継承されます。 
MenuItems フィルター プロバイダーで表示されるツールのリストを返します。
解説

このイベントは、UltraGrid の Infragistics.Win.UltraWinGrid.UltraGridBase.BeforeRowFilterDropDown イベント後に発生します。グリッドのイベントの目的は階層コンテンツを生成することですが、このイベントの目的、対応する AfterMenuPopulate は、フィルター プロバイダーが表示される時に現れるさまざまなメニュー項目の作成や配置の処理です。

注: このイベントをマークすると、プロバイダーが階層を含むすべての標準項目の追加を禁止します。FilterTreeTool は、手動で作成されるので、この要素を再配置したい場合は、AfterMenuPopulate イベントを代わりに使用する必要があります。

使用例
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);
}
参照