using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Infragistics.Win;
using Infragistics.Win.AppStyling;
using Infragistics.Win.AppStyling.Runtime;
using Infragistics.Win.UltraWinGrid;
using System.Drawing.Imaging;
namespace Filter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.grid.InitializeLayout += new InitializeLayoutEventHandler(grid_InitializeLayout);
this.grid.BeforeRowFilterDropDownPopulate += new BeforeRowFilterDropDownPopulateEventHandler(grid_BeforeRowFilterDropDownPopulate);
this.grid.DataSource = this.Table;
}
void grid_BeforeRowFilterDropDownPopulate(object sender, BeforeRowFilterDropDownPopulateEventArgs e)
{
e.Handled = true;
e.ValueList.ValueListItems.Clear();
e.ValueList.ValueListItems.Add( “(All)” );
e.ValueList.ValueListItems.Add( new RangeConditionInt32(e.Column, 2, 4) );
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
void grid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
e.Layout.Bands[0].Columns[1].AllowRowFiltering = DefaultableBoolean.True;
}
private DataTable Table
{
get
{
DataTable table = new DataTable();
table.Columns.Add(“col1”, typeof(string));
table.Columns.Add(“col2”, typeof(int));
for (int i = 0; i < 100000; i++)
{
table.Rows.Add( new object[]{“a”, 1} );
table.Rows.Add( new object[]{“b”, 2} );
table.Rows.Add( new object[]{“c”, 3} );
table.Rows.Add( new object[]{“d”, 4} );
table.Rows.Add( new object[]{“e”, 5} );
table.Rows.Add( new object[]{“f”, 6} );
table.Rows.Add( new object[]{“g”, 7} );
table.Rows.Add( new object[]{“h”, 8} );
table.Rows.Add( new object[]{“i”, 9} );
table.Rows.Add( new object[]{“j”, 10} );
}
return table;
}
}
}
public class RangeConditionInt32 : FilterCondition
{
public RangeConditionInt32( UltraGridColumn column, int min, int max )
{
this.Column = column;
this.Min = min;
this.Max = max;
}
public new UltraGridColumn Column { get; private set; }
public int Min { get; private set; }
public int Max { get; private set; }
public override bool MeetsCriteria(UltraGridRow row)
{
object cellValue = row.Cells[this.Column].Value;
if ( (cellValue is int) == false )
return false;
int val = (int)(row.Cells[this.Column].Value);
return val >= this.Min && val <= this.Max;
}
public override string ToString()
{
return string.Format(“x >= {0} && x <= {1}”, this.Min, this.Max);
}
}
}