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