Infragistics(R) NetAdvantage(R) Windows Forms
ColumnFilter Class
Members  Example  See Also  E-mail your feedback on this topic.
Infragistics.Win.UltraWinGrid Namespace : ColumnFilter Class

ColumnFilter class.

Syntax

Visual Basic (Declaration) 
Public Class ColumnFilter 
   Inherits Infragistics.Shared.KeyedSubObjectBase
   Implements Infragistics.Shared.IKeyedSubObject, Infragistics.Shared.IKeyedSubObjectEx 
C# 
public class ColumnFilter : Infragistics.Shared.KeyedSubObjectBase, Infragistics.Shared.IKeyedSubObject, Infragistics.Shared.IKeyedSubObjectEx  

Example

Following code shows some of the information available in BeforeRowFilterDropDown event. It shows how to manipulate the items in the filter drop down and also add custom filter items.

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.

Visual BasicCopy Code
Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid

    Private Sub UltraGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles UltraGrid1.InitializeLayout
        e.Layout.Override.AllowRowFiltering = DefaultableBoolean.True
    End Sub

    Private Sub UltraGrid1_BeforeRowFilterDropDown(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeRowFilterDropDownEventArgs) Handles UltraGrid1.BeforeRowFilterDropDown
        ' You can modify the ValueList in the event args. Following for loop removes
        ' Custom and Blanks items from the value list.
        Dim i As Integer
        For i = e.ValueList.ValueListItems.Count - 1 To 0 Step -1
            ' Remove Custom option from the filter drop down.
            If e.ValueList.ValueListItems(i).DisplayText.Equals("(Custom)") Then
                e.ValueList.ValueListItems.RemoveAt(i)
            End If

            ' Remove Blanks option from the filter drop down.
            If e.ValueList.ValueListItems(i).DisplayText.Equals("(Blanks)") Then
                e.ValueList.ValueListItems.RemoveAt(i)
            End If
        Next

        If GetType(String) Is e.Column.DataType Then
            Dim condition As FilterCondition
            ' You can add items with custom criteria as well by using FilterCondition object
            ' as the DataValue of the value list item.				
            condition = New FilterCondition(e.Column, FilterComparisionOperator.Match, "^[A-Ha-h]")
            e.ValueList.ValueListItems.Insert(0, condition, "A to H")

            condition = New FilterCondition(e.Column, FilterComparisionOperator.Match, "^[I-Pi-p]")
            e.ValueList.ValueListItems.Insert(1, condition, "I to P")

            condition = New FilterCondition(e.Column, FilterComparisionOperator.Match, "^[Q-Zq-z]")
            e.ValueList.ValueListItems.Insert(2, condition, "Q to Z")
        End If

        If GetType(Integer) Is e.Column.DataType Then
            Dim conditions As ColumnFilter
            ' You can also add items with custom criteria by using ColumnFilter object
            ' as the DataValue of the value list item.
            conditions = New ColumnFilter(e.Column, FilterLogicalOperator.And)
            conditions.FilterConditions.Add(FilterComparisionOperator.LessThan, 50)
            e.ValueList.ValueListItems.Insert(0, conditions, "49 and below")

            conditions = New ColumnFilter(e.Column, FilterLogicalOperator.And)
            conditions.FilterConditions.Add(FilterComparisionOperator.GreaterThanOrEqualTo, 50)
            conditions.FilterConditions.Add(FilterComparisionOperator.LessThan, 100)
            e.ValueList.ValueListItems.Insert(0, conditions, "50 to 99")

            conditions = New ColumnFilter(e.Column, FilterLogicalOperator.And)
            conditions.FilterConditions.Add(FilterComparisionOperator.GreaterThanOrEqualTo, 100)
            e.ValueList.ValueListItems.Insert(0, conditions, "100 and above")
        End If
    End Sub
C#Copy Code
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

		private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
		{
			e.Layout.Override.AllowRowFiltering = DefaultableBoolean.True;
		}

		private void ultraGrid1_BeforeRowFilterDropDown(object sender, Infragistics.Win.UltraWinGrid.BeforeRowFilterDropDownEventArgs e)
		{
			// You can modify the ValueList in the event args. Following for loop removes
			// Custom and Blanks items from the value list.
			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( "(Custom)" ) )
					e.ValueList.ValueListItems.RemoveAt( i );

				// Remove Blanks option from the filter drop down.
				if ( e.ValueList.ValueListItems[i].DisplayText.Equals( "(Blanks)" ) )
					e.ValueList.ValueListItems.RemoveAt( i );
			}

			if ( typeof( string) == e.Column.DataType )
			{
				FilterCondition condition;
				// You can add items with custom criteria as well by using FilterCondition object
				// as the DataValue of the value list item.				
				condition = new FilterCondition( e.Column, FilterComparisionOperator.Match, "^[A-Ha-h]" );
				e.ValueList.ValueListItems.Insert( 0, condition, "A to H" );

				condition = new FilterCondition( e.Column, FilterComparisionOperator.Match, "^[I-Pi-p]" );
				e.ValueList.ValueListItems.Insert( 1, condition, "I to P" );

				condition = new FilterCondition( e.Column, FilterComparisionOperator.Match, "^[Q-Zq-z]" );
				e.ValueList.ValueListItems.Insert( 2, condition, "Q to Z" );
			}

			if ( typeof( int ) == e.Column.DataType )
			{
				ColumnFilter conditions;
				// You can also add items with custom criteria by using ColumnFilter object
				// as the DataValue of the value list item.
				conditions = new ColumnFilter( e.Column, FilterLogicalOperator.And );
				conditions.FilterConditions.Add( FilterComparisionOperator.LessThan, 50 );
				e.ValueList.ValueListItems.Insert( 0, conditions, "49 and below" );
				
				conditions = new ColumnFilter( e.Column, FilterLogicalOperator.And );
				conditions.FilterConditions.Add( FilterComparisionOperator.GreaterThanOrEqualTo, 50 );
				conditions.FilterConditions.Add( FilterComparisionOperator.LessThan, 100 );
				e.ValueList.ValueListItems.Insert( 0, conditions, "50 to 99" );

				conditions = new ColumnFilter( e.Column, FilterLogicalOperator.And );
				conditions.FilterConditions.Add( FilterComparisionOperator.GreaterThanOrEqualTo, 100 );
				e.ValueList.ValueListItems.Insert( 0, conditions, "100 and above" );
			}
		}

Remarks

A FilterCondition object defines a single condition. Multiple FilterCondition instances can be added to the FilterConditionsCollection. A ColumnFilter instance contains a FilterConditionsCollection instance. The ColumnFilter has LogicalOperator property which specifies how multiple conditions contained in the ColumnFilter's FilterConditionCollection are to be combined. A ColumnFiltersCollection can contain multiple ColumnFilter instances. Both the UltraGridBand and RowsCollection objects expose ColumnFilters property. This property returns a collection of ColumnFilter objects. UltraGrid will filter rows using either the RowsCollection's RowsCollection.ColumnFilters or UltraGridBand's UltraGridBand.ColumnFilters depending on the what the Override's UltraGridOverride.RowFilterMode property is set to. See UltraGridOverride.RowFilterMode for more information.

See Also