Version

FilterComparisionOperator Enumeration

Enum for specifying the comparision operator.
Syntax
'Declaration
 
Public Enum FilterComparisionOperator 
   Inherits System.Enum
public enum FilterComparisionOperator : System.Enum 
Members
MemberDescription
ContainsTests to see if the cell value contains the operand.
CustomUsed for creating custom filters. This is used when deriving a class from FilterCondition and implementing custom logic for filter evaluation by overriding the MeetsCriteria method of in the derived class. Default implementation of MeetsCriteria always returns true for Custom filter comparision operator and thus it's necessary to derive from FilterCondition and override the MeetsCriteria for custom filters.
DoesNotContainComplement of Contains.
DoesNotEndWithComplement of EndsWith.
DoesNotMatchComplement of Match.
DoesNotStartWithComplement of StartsWith.
EndsWithTests to see if the cell value ends with the operand.
EqualsTests for two values being equal.
GreaterThanTests for the column's value being greater than the value.
GreaterThanOrEqualToTests for the column's value being greater than or equal to the value.
InTests to see if the value is one of specified values.
LessThanTests for the column's value being less than the value.
LessThanOrEqualToTests for the column's value being less than or equal to the value.
LikeWill do a wildcard comparision of the column's value to the comparision value taking comparision value as the string with wild cards.
MatchWill do a regular expression comparision of the column's value to the comparision value taking comparision value as regular expression string.
NotEqualsTests for two values being not equal.
NotInTests to see if the value is not one of specified values.
NotLikeComplement of Like.
StartsWithTests to see if the cell value starts with the operand.
Example
Following code demonstrates how to use custom filter criteria to filter rows. It derives a class from FilterCondition and overrides the MeetsCriteria method to filter rows based on custom filter criteria. The custom filter condition in this case is a filter condition that filters rows based on whether the cell's value is odd or even. The constructor takes in an arguement that specifies whether to pass rows with odd values or even values. The sample code also hooks into the BeforeRowFilterDropDown event of the grid and adds Odd and Even items to the filter drop down of the column with Col1 as its key. When the filter drop down is dropped down, the user will see Odd and Even items in the drop down.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid

    ' Derive a class from FilterCondition to create a custom filter criteria.
    ' Mark the class Serializable. This is only necessary if you intend to serialize 
    ' the filter condition object (Load and Save layouts with this filter applied).
    <Serializable()> _
    Private Class OddEvenFilterCondition
        Inherits FilterCondition

        ' This is only necessary if you intend to serialize the filter condition object.
        ' (Load and Save layouts with this filter applied).
        Protected Sub New( _
        ByVal info As System.Runtime.Serialization.SerializationInfo, _
        ByVal context As System.Runtime.Serialization.StreamingContext)
            MyBase.New(info, context)
        End Sub

        Sub New(ByVal column As UltraGridColumn, ByVal odd As Boolean)
            MyBase.New(column, FilterComparisionOperator.Custom, Nothing)

            ' Store any necessary information to the CompareValue property because the
            ' base class serializes the CompareValue. This is only necessary if you 
            ' intend to serialize filter condition object (Load and Save layouts with 
            ' this filter applied) and don't want to write your own code for serializing
            ' the information.
            Me.CompareValue = odd
        End Sub

        ' Override MeetsCriteria method and write your own code for filtering the row.
        Public Overrides Function MeetsCriteria(ByVal row As UltraGridRow) As Boolean

            ' Following code filters out the rows with odd or even values depending on
            ' the whether compare value is set to true or false.
            ' Following code filters out the rows with odd or even values depending on
            ' the whether compare value is set to true or false.
            Dim cellVal As Object = row.GetCellValue(Me.Column)
            Try
                Dim val As Integer = Convert.ToInt32(cellVal)

                Dim odd As Boolean = DirectCast(Me.CompareValue, Boolean)

                If odd Then
                    Return 1 = val Mod 2
                Else
                    Return 0 = val Mod 2
                End If
            Catch e As Exception
                ' Cell value was either DBNull or something that could not be converted
                ' to int. Return true to pass the row so that it's visible. (You could
                ' return false here if you want such rows to get hidden).
            End Try

        End Function
    End Class

    Private Sub UltraGrid1_BeforeRowFilterDropDown(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeRowFilterDropDownEventArgs) Handles UltraGrid1.BeforeRowFilterDropDown
        If e.Column.Key = "Col1" Then
            ' Clear all items from the filter drop down except (All) which allows the user
            ' to clear the filters on the column.
            Dim i As Integer
            For i = e.ValueList.ValueListItems.Count - 1 To 0 Step -1
                ' Remove Custom option from the filter drop down.
                If Not e.ValueList.ValueListItems(i).DisplayText.Equals("(All)") Then
                    e.ValueList.ValueListItems.RemoveAt(i)
                End If
            Next

            ' Add two items one that filters in rows that are odd and one that filters in rows
            ' that are even.
            e.ValueList.ValueListItems.Add(New OddEvenFilterCondition(e.Column, True), "Odd")
            e.ValueList.ValueListItems.Add(New OddEvenFilterCondition(e.Column, False), "Even")
        End If
    End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

		// Derive a class from FilterCondition to create a custom filter criteria.
		// Mark the class Serializable. This is only necessary if you intend to serialize 
		// the filter condition object (Load and Save layouts with this filter applied).
		[ Serializable() ]
		private class OddEvenFilterCondition : FilterCondition
		{
			// This is only necessary if you intend to serialize the filter condition object.
			// (Load and Save layouts with this filter applied).
			/// <summary>
			/// Constructor for serialization.
			/// </summary>
			/// <param name="info"></param>
			/// <param name="context"></param>
			protected OddEvenFilterCondition( 
				System.Runtime.Serialization.SerializationInfo info, 
				System.Runtime.Serialization.StreamingContext context )
				: base( info, context )
			{
			}

			/// <summary>
			/// Constructor.
			/// </summary>
			/// <param name="column"></param>
			/// <param name="odd"></param>
			internal OddEvenFilterCondition( UltraGridColumn column, bool odd ) : 
				base( column, FilterComparisionOperator.Custom, null )
			{
				// Store any necessary information to the CompareValue property because the
				// base class serializes the CompareValue. This is only necessary if you 
				// intend to serialize filter condition object (Load and Save layouts with 
				// this filter applied) and don't want to write your own code for serializing
				// the information.
				this.CompareValue = odd;
			}

			// Override MeetsCriteria method and write your own code for filtering the row.
			public override bool MeetsCriteria( UltraGridRow row )
			{
				// Following code filters out the rows with odd or even values depending on
				// the whether compare value is set to true or false.
				object cellVal = row.GetCellValue( this.Column );
				try
				{
					int val = Convert.ToInt32( cellVal );
					
					bool odd = (bool)this.CompareValue;
					if ( odd )
						return 1 == val % 2;
					else
						return 0 == val % 2;
				}
				catch ( Exception )
				{
					// Cell value was either DBNull or something that could not be converted
					// to int. Return true to pass the row so that it's visible. (You could
					// return false here if you want such rows to get hidden).
					return true;
				}
			}
		}

		private void ultraGrid1_BeforeRowFilterDropDown(object sender, Infragistics.Win.UltraWinGrid.BeforeRowFilterDropDownEventArgs e)
		{
			if ( e.Column.Key == "Col1" )
			{
				// Clear all items from the filter drop down except (All) which allows the user
				// to clear the filters on the column.
				for ( int i = e.ValueList.ValueListItems.Count - 1; i >= 0; i-- )
				{
					// Remove Custom option from the filter drop down.
					if ( ! e.ValueList.ValueListItems[i].DisplayText.Equals( "(All)" ) )
						e.ValueList.ValueListItems.RemoveAt( i );
				}

				// Add two items one that filters in rows that are odd and one that filters in rows
				// that are even.
				e.ValueList.ValueListItems.Add( new OddEvenFilterCondition( e.Column, true ), "Odd" );
				e.ValueList.ValueListItems.Add( new OddEvenFilterCondition( e.Column, false ), "Even" );
			}
		}
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