How to: Create a Custom Filter Dropdown
- 3 minutes to read
To create a custom drop-down filter:
- Set the column’s ColumnBase.FilterPopupMode property to FilterPopupMode.Custom.
- Create a template representing the required drop-down filter and assign it to the ColumnBase.CustomColumnFilterPopupTemplate property.
This example demonstrates how to create a custom drop-down filter for the Index column.
The image below shows the result:
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-create-a-custom-filter-dropdown-e1616.
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Markup;
using DevExpress.Data.Filtering;
namespace DXGrid_CustomFilterPopup {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
grid.ItemsSource = GridData.GetData();
}
}
public class GridData {
static public List<DataObject> GetData() {
List<DataObject> data = new List<DataObject>();
for (int i = 0; i < 100; i++)
data.Add(new DataObject() { Index = i });
return data;
}
}
public class DataObject {
public int Index { get; set; }
}
public class IntToCriteriaOperatorConverter : MarkupExtension, IValueConverter {
public override object ProvideValue(IServiceProvider serviceProvider) {
return this;
}
#region IValueConverter Members
object IValueConverter.Convert(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture) {
BinaryOperator op = value as BinaryOperator;
if (object.ReferenceEquals(op, null))
return null;
OperandValue operandValue = op.RightOperand as OperandValue;
return operandValue.Value;
}
object IValueConverter.ConvertBack(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture) {
return new BinaryOperator("Index", Convert.ToInt32(value), BinaryOperatorType.Greater);
}
#endregion
}
}