'Declaration Public MustOverride Function SupportsOperator( _ ByVal comparisonOperator As FilterComparisionOperator _ ) As Boolean
public abstract bool SupportsOperator( FilterComparisionOperator comparisonOperator )
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); }
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