FilterControl.MaxOperandsCount Property
Gets or sets the maximum number of atomic operands simultaneously displayed within a group operand. If there are more atomic operands in display mode, the group operand’s text representation will be trimmed. In edit mode, the group operand’s values will be edited via a CheckedComboBoxEdit control. This feature is supported when the FilterControl is bound to XtraGrid.
Namespace: DevExpress.XtraEditors
Assembly: DevExpress.XtraEditors.v24.1.dll
NuGet Package: DevExpress.Win.Navigation
Declaration
[DefaultValue(20)]
[DXCategory("Behavior")]
public int MaxOperandsCount { get; set; }
<DXCategory("Behavior")>
<DefaultValue(20)>
Public Property MaxOperandsCount As Integer
Property Value
Type | Default | Description |
---|---|---|
Int32 | 20 | An integer value that specifies the maximum number of atomic operands simultaneously displayed within a group operand. |
Remarks
Group operands are used to define values for the Is any of and Is none of operators:
If the number of atomic operands in a group operand is equal to or less than MaxOperandsCount, the FilterControl displays all the atomic operands, separating them with a comma. Each operand can be edited within a separate edit box:
If the number of atomic operands is greater than MaxOperandsCount, the following takes place if the FilterControl is bound to Grid Control via the FilterControl.SourceControl property:
in display mode, the group operand’s text representation is trimmed.
in edit mode, the group operand is edited via a CheckedComboBoxEdit control.
If the FilterControl is not bound to XtraGrid, the CheckedComboBoxEdit control can still be used to present a group operand’s value. The following example shows how to accomplish this.
Example - How to use CheckedComboBox control when editing IsAnyOf and IsNoneOf operands in FilterControl bound to any object except XtraGrid
In FilterControl, there are two operand presentation modes when editing the "Is Any Of" and "Is None Of" group operands: simple and advanced. The simple mode is enabled when the number of atomic operands in a group operand is equal to or less than FilterControl.MaxOperandCount. Otherwise the advanced mode is activated, where:- in display mode, a group operand's text presentation is trimmed.- in edit mode, the group operand's values are edited with the help of the CheckedComboBoxEdit control. The advanced operand presentation mode is supported when the FilterControl is bound to the XtraGrid. Otherwise, this feature is not supported. This example shows how to overcome this limitation by creating a custom SourceControl component and an UnbounFilterColumn descendant.In the descendant class two members are overridden:- The AllowItemCollectionEditor property determines whether or not the feature is allowed for certain columns.- The CreateItemCollectionEditor method creates a CheckedComboBoxEdit control.
- Program.cs
- CustomFilterColumn.cs
- DataTableHelper.cs
- FilterAdapter.cs
- Form1.cs
- Program.vb
- CustomFilterColumn.vb
- Form1.vb
- DataTableHelper.vb
- FilterAdapter.vb
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace B217847Example
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
using System;
using System.Linq;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using DevExpress.XtraEditors.Filtering;
using DevExpress.XtraEditors.Repository;
using DevExpress.Data.Filtering.Helpers;
namespace B217847Example
{
class CustomFilterColumn : UnboundFilterColumn
{
public CustomFilterColumn(string columnCaption, string fieldName, Type columnType,
RepositoryItem columnEdit, FilterColumnClauseClass clauseClass, FilterAdapter owner)
: base(columnCaption, fieldName, columnType, columnEdit, clauseClass) {
this.Owner = owner;
}
protected readonly FilterAdapter Owner;
Object DataSource {
get { return Owner.DataSource; }
}
private void GetAllUniqueValues(IList List, List<Object> op)
{
foreach (object Lob in List)
{
foreach (PropertyDescriptor pd in Owner.GetProperties())
{
if (pd.Name == FieldName)
op.Add(pd.GetValue(Lob));
}
}
}
public override RepositoryItem CreateItemCollectionEditor()
{
FilterRepositoryItemCheckedComboBoxEdit re = new FilterRepositoryItemCheckedComboBoxEdit();
if (DataSource == null)
return re;
IList List;
if (DataSource is IList)
List = DataSource as IList;
else
{
IListSource Ilist = DataSource as IListSource;
List = Ilist.GetList();
}
List<Object> op = new List<object>();
GetAllUniqueValues(List, op);
foreach (Object Value in op)
{
if (Value.ToString() != "" && re.Items[Value] == null)
re.Items.Add(Value, Value.ToString());
}
return re;
}
public override bool AllowItemCollectionEditor
{
get
{
return true;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace B217847Example
{
public class DataTableHelper
{
public static void GetDataTable(DataTable table)
{
DataRow Row1 = table.NewRow();
Row1["Number"] = 23;
Row1["Name"] = "Mike";
Row1["Date"] = new DateTime(2012, 9, 18);
table.Rows.Add(Row1);
DataRow Row2 = table.NewRow();
Row2["Number"] = 12;
Row2["Name"] = "Jon";
Row2["Date"] = new DateTime(2012, 9, 19);
table.Rows.Add(Row2);
DataRow Row3 = table.NewRow();
Row3["Number"] = 1;
Row3["Name"] = "Bill";
Row3["Date"] = new DateTime(2012, 9, 20);
table.Rows.Add(Row3);
DataRow Row4 = table.NewRow();
Row4["Number"] = 121;
Row4["Name"] = "Bruce";
Row4["Date"] = new DateTime(2012, 9, 21);
table.Rows.Add(Row4);
DataRow Row5 = table.NewRow();
Row5["Number"] = 132;
Row5["Name"] = "Lex";
Row5["Date"] = new DateTime(2012, 9, 22);
table.Rows.Add(Row5);
}
}
}
using System;
using System.Linq;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using DevExpress.XtraEditors.Filtering;
using DevExpress.XtraEditors.Repository;
using DevExpress.Data.Filtering;
using DevExpress.Data.Filtering.Helpers;
namespace B217847Example
{
[ToolboxItem(true)]
public class FilterAdapter :Component, IFilteredComponent, ISupportInitialize
{
[AttributeProvider(typeof(IListSource))]
public object DataSource
{
get { return fDataSource; }
set
{
IBindingList oldBindingList = fDataSource as IBindingList;
if (oldBindingList != null)
oldBindingList.ListChanged -= OnListChanged;
fDataSource = value;
IBindingList newBindingList = fDataSource as IBindingList;
if (newBindingList != null)
newBindingList.ListChanged += OnListChanged;
}
}
CriteriaOperator fRowCriteria;
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual CriteriaOperator RowCriteria
{
get { return fRowCriteria; }
set {
if (ReferenceEquals(fRowCriteria, value)) return;
fRowCriteria = value;
RaiseRowFilterChanged();
}
}
private object fDataSource;
static RepositoryItemTextEdit DefaultEditor = new RepositoryItemTextEdit();
static RepositoryItemDateEdit DefaultDateEditor = new RepositoryItemDateEdit();
protected virtual FilterColumnCollection GetFilterColumns()
{
PropertyDescriptorCollection PDC = GetProperties();
List<PropertyDescriptor> td = FilterPropertyDescriptionCollection(PDC);
return GetFilterColumnsCollection(td);
}
public PropertyDescriptorCollection GetProperties()
{
IList list = DataSource as IList;
if (list == null)
if (DataSource is IListSource)
list = ((IListSource)DataSource).GetList();
if (list == null)
return new PropertyDescriptorCollection(new PropertyDescriptor[0], true);
ITypedList typedList = list as ITypedList;
if (typedList == null)
{
if (list.Count > 0)
return TypeDescriptor.GetProperties(list[0]);
}
else return typedList.GetItemProperties(new PropertyDescriptor[0]);
return new PropertyDescriptorCollection(new PropertyDescriptor[0], true);
}
private static List<PropertyDescriptor> FilterPropertyDescriptionCollection(PropertyDescriptorCollection PDC)
{
List<PropertyDescriptor> td = new List<PropertyDescriptor>();
foreach (PropertyDescriptor pd in PDC)
{
object op = pd.PropertyType;
if (!pd.PropertyType.IsClass || (pd.PropertyType == typeof(string)))
td.Add(pd);
}
return td;
}
private FilterColumnCollection GetFilterColumnsCollection(List<PropertyDescriptor> td)
{
FilterColumnCollection filterCollection = new FilterColumnCollection();
foreach (PropertyDescriptor pd in td)
{
CustomFilterColumn UFC = new CustomFilterColumn(pd.DisplayName, pd.Name,
pd.PropertyType, GetDefaultEditor(pd.PropertyType), GetClauseClass(pd.PropertyType), this);
filterCollection.Add(UFC);
}
return filterCollection;
}
static FilterColumnClauseClass GetClauseClass(Type type)
{
if (type == typeof(string))
return FilterColumnClauseClass.String;
if (type == typeof(DateTime))
return FilterColumnClauseClass.DateTime;
return FilterColumnClauseClass.Generic;
}
static RepositoryItem GetDefaultEditor(Type type)
{
if (type == typeof(DateTime))
return DefaultDateEditor;
return DefaultEditor;
}
private void OnListChanged(object sender, ListChangedEventArgs e)
{
if (e.ListChangedType == ListChangedType.PropertyDescriptorAdded ||
e.ListChangedType == ListChangedType.PropertyDescriptorDeleted ||
e.ListChangedType == ListChangedType.PropertyDescriptorChanged)
RaisePropertiesChanged();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
IBindingList oldBindingList = fDataSource as IBindingList;
if (oldBindingList != null)
oldBindingList.ListChanged -= OnListChanged;
}
base.Dispose(disposing);
}
public event EventHandler RowFilterChanged
{
add { Events.AddHandler(fRowFilterChanged, value); }
remove { Events.RemoveHandler(fRowFilterChanged, value); }
}
#region IFilteredComponent
IBoundPropertyCollection IFilteredComponent.CreateFilterColumnCollection()
{
if (Initializing) return new FilterColumnCollection();
return GetFilterColumns();
}
static readonly object fPropertiesChanged = new object();
event EventHandler IFilteredComponentBase.PropertiesChanged
{
add { Events.AddHandler(fPropertiesChanged, value); }
remove { Events.RemoveHandler(fPropertiesChanged, value); }
}
void RaisePropertiesChanged()
{
EventHandler handler = Events[fPropertiesChanged] as EventHandler;
if (handler != null)
handler(this, EventArgs.Empty);
}
CriteriaOperator IFilteredComponentBase.RowCriteria
{
get { return RowCriteria; }
set { RowCriteria = value; }
}
static readonly object fRowFilterChanged = new object();
event EventHandler IFilteredComponentBase.RowFilterChanged
{
add { RowFilterChanged += value; }
remove { RowFilterChanged -= value; }
}
void RaiseRowFilterChanged()
{
EventHandler handler = Events[fRowFilterChanged] as EventHandler;
if (handler != null)
handler(this, EventArgs.Empty);
}
#endregion
#region ISupportInitialize
bool Initializing;
void ISupportInitialize.BeginInit()
{
Initializing = true;
}
void ISupportInitialize.EndInit()
{
Initializing = false;
RaisePropertiesChanged();
}
#endregion
}
}
using System;
using System.Linq;
using System.Windows.Forms;
using System.Collections.Generic;
namespace B217847Example
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DataTableHelper.GetDataTable(dtTest);
}
private void OnFilterAdapterRowFilterChanged(object sender, EventArgs e)
{
gridView1.ActiveFilterCriteria = filterAdapter1.RowCriteria;
}
private void OnApplyFilterButtonClick(object sender, EventArgs e)
{
filterControl1.ApplyFilter();
}
}
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Windows.Forms
Namespace B217847Example
Friend NotInheritable Class Program
''' <summary>
''' The main entry point for the application.
''' </summary>
Private Sub New()
End Sub
<STAThread> _
Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1())
End Sub
End Class
End Namespace
Imports Microsoft.VisualBasic
Imports System
Imports System.Linq
Imports System.Collections
Imports System.ComponentModel
Imports System.Collections.Generic
Imports DevExpress.XtraEditors.Filtering
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.Data.Filtering.Helpers
Namespace B217847Example
Friend Class CustomFilterColumn
Inherits UnboundFilterColumn
Public Sub New(ByVal columnCaption As String, ByVal fieldName As String, ByVal columnType As Type, ByVal columnEdit As RepositoryItem, ByVal clauseClass As FilterColumnClauseClass, ByVal owner As FilterAdapter)
MyBase.New(columnCaption, fieldName, columnType, columnEdit, clauseClass)
Me.Owner = owner
End Sub
Protected ReadOnly Owner As FilterAdapter
Private ReadOnly Property DataSource() As Object
Get
Return Owner.DataSource
End Get
End Property
Private Sub GetAllUniqueValues(ByVal List As IList, ByVal op As List(Of Object))
For Each Lob As Object In List
For Each pd As PropertyDescriptor In Owner.GetProperties()
If pd.Name = FieldName Then
op.Add(pd.GetValue(Lob))
End If
Next pd
Next Lob
End Sub
Public Overrides Function CreateItemCollectionEditor() As RepositoryItem
Dim re As New FilterRepositoryItemCheckedComboBoxEdit()
If DataSource Is Nothing Then
Return re
End If
Dim List As IList
If TypeOf DataSource Is IList Then
List = TryCast(DataSource, IList)
Else
Dim Ilist As IListSource = TryCast(DataSource, IListSource)
List = Ilist.GetList()
End If
Dim op As New List(Of Object)()
GetAllUniqueValues(List, op)
For Each Value As Object In op
If Value.ToString() <> "" AndAlso re.Items(Value) Is Nothing Then
re.Items.Add(Value, Value.ToString())
End If
Next Value
Return re
End Function
Public Overrides ReadOnly Property AllowItemCollectionEditor() As Boolean
Get
Return True
End Get
End Property
End Class
End Namespace
Imports Microsoft.VisualBasic
Imports System
Imports System.Linq
Imports System.Windows.Forms
Imports System.Collections.Generic
Namespace B217847Example
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
DataTableHelper.GetDataTable(dtTest)
End Sub
Private Sub OnFilterAdapterRowFilterChanged(ByVal sender As Object, ByVal e As EventArgs) Handles filterAdapter1.RowFilterChanged
gridView1.ActiveFilterCriteria = filterAdapter1.RowCriteria
End Sub
Private Sub OnApplyFilterButtonClick(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton1.Click
filterControl1.ApplyFilter()
End Sub
End Class
End Namespace
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Data
Namespace B217847Example
Public Class DataTableHelper
Public Shared Sub GetDataTable(ByVal table As DataTable)
Dim Row1 As DataRow = table.NewRow()
Row1("Number") = 23
Row1("Name") = "Mike"
Row1("Date") = New DateTime(2012, 9, 18)
table.Rows.Add(Row1)
Dim Row2 As DataRow = table.NewRow()
Row2("Number") = 12
Row2("Name") = "Jon"
Row2("Date") = New DateTime(2012, 9, 19)
table.Rows.Add(Row2)
Dim Row3 As DataRow = table.NewRow()
Row3("Number") = 1
Row3("Name") = "Bill"
Row3("Date") = New DateTime(2012, 9, 20)
table.Rows.Add(Row3)
Dim Row4 As DataRow = table.NewRow()
Row4("Number") = 121
Row4("Name") = "Bruce"
Row4("Date") = New DateTime(2012, 9, 21)
table.Rows.Add(Row4)
Dim Row5 As DataRow = table.NewRow()
Row5("Number") = 132
Row5("Name") = "Lex"
Row5("Date") = New DateTime(2012, 9, 22)
table.Rows.Add(Row5)
End Sub
End Class
End Namespace
Imports Microsoft.VisualBasic
Imports System
Imports System.Linq
Imports System.Collections
Imports System.ComponentModel
Imports System.Collections.Generic
Imports DevExpress.XtraEditors.Filtering
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.Data.Filtering
Imports DevExpress.Data.Filtering.Helpers
Namespace B217847Example
<ToolboxItem(True)> _
Public Class FilterAdapter
Inherits Component
Implements IFilteredComponent, ISupportInitialize
<AttributeProvider(GetType(IListSource))> _
Public Property DataSource() As Object
Get
Return fDataSource
End Get
Set(ByVal value As Object)
Dim oldBindingList As IBindingList = TryCast(fDataSource, IBindingList)
If oldBindingList IsNot Nothing Then
RemoveHandler oldBindingList.ListChanged, AddressOf OnListChanged
End If
fDataSource = value
Dim newBindingList As IBindingList = TryCast(fDataSource, IBindingList)
If newBindingList IsNot Nothing Then
AddHandler newBindingList.ListChanged, AddressOf OnListChanged
End If
End Set
End Property
Private fRowCriteria As CriteriaOperator
<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Overridable Property RowCriteria() As CriteriaOperator
Get
Return fRowCriteria
End Get
Set(ByVal value As CriteriaOperator)
If ReferenceEquals(fRowCriteria, value) Then
Return
End If
fRowCriteria = value
RaiseRowFilterChanged()
End Set
End Property
Private fDataSource As Object
Private Shared DefaultEditor As New RepositoryItemTextEdit()
Private Shared DefaultDateEditor As New RepositoryItemDateEdit()
Protected Overridable Function GetFilterColumns() As FilterColumnCollection
Dim PDC As PropertyDescriptorCollection = GetProperties()
Dim td As List(Of PropertyDescriptor) = FilterPropertyDescriptionCollection(PDC)
Return GetFilterColumnsCollection(td)
End Function
Public Function GetProperties() As PropertyDescriptorCollection
Dim list As IList = TryCast(DataSource, IList)
If list Is Nothing Then
If TypeOf DataSource Is IListSource Then
list = (CType(DataSource, IListSource)).GetList()
End If
End If
If list Is Nothing Then
Return New PropertyDescriptorCollection(New PropertyDescriptor(){}, True)
End If
Dim typedList As ITypedList = TryCast(list, ITypedList)
If typedList Is Nothing Then
If list.Count > 0 Then
Return TypeDescriptor.GetProperties(list(0))
End If
Else
Return typedList.GetItemProperties(New PropertyDescriptor(){})
End If
Return New PropertyDescriptorCollection(New PropertyDescriptor(){}, True)
End Function
Private Shared Function FilterPropertyDescriptionCollection(ByVal PDC As PropertyDescriptorCollection) As List(Of PropertyDescriptor)
Dim td As New List(Of PropertyDescriptor)()
For Each pd As PropertyDescriptor In PDC
Dim op As Object = pd.PropertyType
If (Not pd.PropertyType.IsClass) OrElse (pd.PropertyType Is GetType(String)) Then
td.Add(pd)
End If
Next pd
Return td
End Function
Private Function GetFilterColumnsCollection(ByVal td As List(Of PropertyDescriptor)) As FilterColumnCollection
Dim filterCollection As New FilterColumnCollection()
For Each pd As PropertyDescriptor In td
Dim UFC As New CustomFilterColumn(pd.DisplayName, pd.Name, pd.PropertyType, GetDefaultEditor(pd.PropertyType), GetClauseClass(pd.PropertyType), Me)
filterCollection.Add(UFC)
Next pd
Return filterCollection
End Function
Private Shared Function GetClauseClass(ByVal type As Type) As FilterColumnClauseClass
If type Is GetType(String) Then
Return FilterColumnClauseClass.String
End If
If type Is GetType(DateTime) Then
Return FilterColumnClauseClass.DateTime
End If
Return FilterColumnClauseClass.Generic
End Function
Private Shared Function GetDefaultEditor(ByVal type As Type) As RepositoryItem
If type Is GetType(DateTime) Then
Return DefaultDateEditor
End If
Return DefaultEditor
End Function
Private Sub OnListChanged(ByVal sender As Object, ByVal e As ListChangedEventArgs)
If e.ListChangedType = ListChangedType.PropertyDescriptorAdded OrElse e.ListChangedType = ListChangedType.PropertyDescriptorDeleted OrElse e.ListChangedType = ListChangedType.PropertyDescriptorChanged Then
RaisePropertiesChanged()
End If
End Sub
Protected Overrides Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
Dim oldBindingList As IBindingList = TryCast(fDataSource, IBindingList)
If oldBindingList IsNot Nothing Then
RemoveHandler oldBindingList.ListChanged, AddressOf OnListChanged
End If
End If
MyBase.Dispose(disposing)
End Sub
Public Custom Event RowFilterChanged As EventHandler Implements IFilteredComponent.RowFilterChanged
AddHandler(ByVal value As EventHandler)
Events.AddHandler(fRowFilterChanged, value)
End AddHandler
RemoveHandler(ByVal value As EventHandler)
Events.RemoveHandler(fRowFilterChanged, value)
End RemoveHandler
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
End RaiseEvent
End Event
#Region "IFilteredComponent"
Private Function CreateFilterColumnCollection() As IBoundPropertyCollection Implements IFilteredComponent.CreateFilterColumnCollection
If Initializing Then
Return New FilterColumnCollection()
End If
Return GetFilterColumns()
End Function
Private Shared ReadOnly fPropertiesChanged As Object = New Object()
Private Custom Event PropertiesChanged As EventHandler Implements IFilteredComponentBase.PropertiesChanged
AddHandler(ByVal value As EventHandler)
Events.AddHandler(fPropertiesChanged, value)
End AddHandler
RemoveHandler(ByVal value As EventHandler)
Events.RemoveHandler(fPropertiesChanged, value)
End RemoveHandler
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
End RaiseEvent
End Event
Private Sub RaisePropertiesChanged()
Dim handler As EventHandler = TryCast(Events(fPropertiesChanged), EventHandler)
If handler IsNot Nothing Then
handler(Me, EventArgs.Empty)
End If
End Sub
Private Property IFilteredComponentBase_RowCriteria() As CriteriaOperator Implements IFilteredComponentBase.RowCriteria
Get
Return RowCriteria
End Get
Set(ByVal value As CriteriaOperator)
RowCriteria = value
End Set
End Property
Private Shared ReadOnly fRowFilterChanged As Object = New Object()
Private Custom Event mRowFilterChanged As EventHandler
AddHandler(ByVal value As EventHandler)
AddHandler RowFilterChanged, value
End AddHandler
RemoveHandler(ByVal value As EventHandler)
RemoveHandler RowFilterChanged, value
End RemoveHandler
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
End RaiseEvent
End Event
Private Sub RaiseRowFilterChanged()
Dim handler As EventHandler = TryCast(Events(fRowFilterChanged), EventHandler)
If handler IsNot Nothing Then
handler(Me, EventArgs.Empty)
End If
End Sub
#End Region
#Region "ISupportInitialize"
Private Initializing As Boolean
Private Sub BeginInit() Implements ISupportInitialize.BeginInit
Initializing = True
End Sub
Private Sub EndInit() Implements ISupportInitialize.EndInit
Initializing = False
RaisePropertiesChanged()
End Sub
#End Region
End Class
End Namespace
Example
In FilterControl, there are two operand presentation modes when editing the "Is Any Of" and "Is None Of" group operands: simple and advanced. The simple mode is enabled when the number of atomic operands in a group operand is equal to or less than FilterControl.MaxOperandCount. Otherwise the advanced mode is activated, where:- in display mode, a group operand's text presentation is trimmed.- in edit mode, the group operand's values are edited with the help of the CheckedComboBoxEdit control. The advanced operand presentation mode is supported when the FilterControl is bound to the XtraGrid. Otherwise, this feature is not supported. This example shows how to overcome this limitation by creating a custom SourceControl component and an UnbounFilterColumn descendant.In the descendant class two members are overridden:- The AllowItemCollectionEditor property determines whether or not the feature is allowed for certain columns.- The CreateItemCollectionEditor method creates a CheckedComboBoxEdit control.
- Program.cs
- CustomFilterColumn.cs
- DataTableHelper.cs
- FilterAdapter.cs
- Form1.cs
- Program.vb
- CustomFilterColumn.vb
- Form1.vb
- DataTableHelper.vb
- FilterAdapter.vb
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace B217847Example
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
using System;
using System.Linq;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using DevExpress.XtraEditors.Filtering;
using DevExpress.XtraEditors.Repository;
using DevExpress.Data.Filtering.Helpers;
namespace B217847Example
{
class CustomFilterColumn : UnboundFilterColumn
{
public CustomFilterColumn(string columnCaption, string fieldName, Type columnType,
RepositoryItem columnEdit, FilterColumnClauseClass clauseClass, FilterAdapter owner)
: base(columnCaption, fieldName, columnType, columnEdit, clauseClass) {
this.Owner = owner;
}
protected readonly FilterAdapter Owner;
Object DataSource {
get { return Owner.DataSource; }
}
private void GetAllUniqueValues(IList List, List<Object> op)
{
foreach (object Lob in List)
{
foreach (PropertyDescriptor pd in Owner.GetProperties())
{
if (pd.Name == FieldName)
op.Add(pd.GetValue(Lob));
}
}
}
public override RepositoryItem CreateItemCollectionEditor()
{
FilterRepositoryItemCheckedComboBoxEdit re = new FilterRepositoryItemCheckedComboBoxEdit();
if (DataSource == null)
return re;
IList List;
if (DataSource is IList)
List = DataSource as IList;
else
{
IListSource Ilist = DataSource as IListSource;
List = Ilist.GetList();
}
List<Object> op = new List<object>();
GetAllUniqueValues(List, op);
foreach (Object Value in op)
{
if (Value.ToString() != "" && re.Items[Value] == null)
re.Items.Add(Value, Value.ToString());
}
return re;
}
public override bool AllowItemCollectionEditor
{
get
{
return true;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace B217847Example
{
public class DataTableHelper
{
public static void GetDataTable(DataTable table)
{
DataRow Row1 = table.NewRow();
Row1["Number"] = 23;
Row1["Name"] = "Mike";
Row1["Date"] = new DateTime(2012, 9, 18);
table.Rows.Add(Row1);
DataRow Row2 = table.NewRow();
Row2["Number"] = 12;
Row2["Name"] = "Jon";
Row2["Date"] = new DateTime(2012, 9, 19);
table.Rows.Add(Row2);
DataRow Row3 = table.NewRow();
Row3["Number"] = 1;
Row3["Name"] = "Bill";
Row3["Date"] = new DateTime(2012, 9, 20);
table.Rows.Add(Row3);
DataRow Row4 = table.NewRow();
Row4["Number"] = 121;
Row4["Name"] = "Bruce";
Row4["Date"] = new DateTime(2012, 9, 21);
table.Rows.Add(Row4);
DataRow Row5 = table.NewRow();
Row5["Number"] = 132;
Row5["Name"] = "Lex";
Row5["Date"] = new DateTime(2012, 9, 22);
table.Rows.Add(Row5);
}
}
}
using System;
using System.Linq;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using DevExpress.XtraEditors.Filtering;
using DevExpress.XtraEditors.Repository;
using DevExpress.Data.Filtering;
using DevExpress.Data.Filtering.Helpers;
namespace B217847Example
{
[ToolboxItem(true)]
public class FilterAdapter :Component, IFilteredComponent, ISupportInitialize
{
[AttributeProvider(typeof(IListSource))]
public object DataSource
{
get { return fDataSource; }
set
{
IBindingList oldBindingList = fDataSource as IBindingList;
if (oldBindingList != null)
oldBindingList.ListChanged -= OnListChanged;
fDataSource = value;
IBindingList newBindingList = fDataSource as IBindingList;
if (newBindingList != null)
newBindingList.ListChanged += OnListChanged;
}
}
CriteriaOperator fRowCriteria;
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual CriteriaOperator RowCriteria
{
get { return fRowCriteria; }
set {
if (ReferenceEquals(fRowCriteria, value)) return;
fRowCriteria = value;
RaiseRowFilterChanged();
}
}
private object fDataSource;
static RepositoryItemTextEdit DefaultEditor = new RepositoryItemTextEdit();
static RepositoryItemDateEdit DefaultDateEditor = new RepositoryItemDateEdit();
protected virtual FilterColumnCollection GetFilterColumns()
{
PropertyDescriptorCollection PDC = GetProperties();
List<PropertyDescriptor> td = FilterPropertyDescriptionCollection(PDC);
return GetFilterColumnsCollection(td);
}
public PropertyDescriptorCollection GetProperties()
{
IList list = DataSource as IList;
if (list == null)
if (DataSource is IListSource)
list = ((IListSource)DataSource).GetList();
if (list == null)
return new PropertyDescriptorCollection(new PropertyDescriptor[0], true);
ITypedList typedList = list as ITypedList;
if (typedList == null)
{
if (list.Count > 0)
return TypeDescriptor.GetProperties(list[0]);
}
else return typedList.GetItemProperties(new PropertyDescriptor[0]);
return new PropertyDescriptorCollection(new PropertyDescriptor[0], true);
}
private static List<PropertyDescriptor> FilterPropertyDescriptionCollection(PropertyDescriptorCollection PDC)
{
List<PropertyDescriptor> td = new List<PropertyDescriptor>();
foreach (PropertyDescriptor pd in PDC)
{
object op = pd.PropertyType;
if (!pd.PropertyType.IsClass || (pd.PropertyType == typeof(string)))
td.Add(pd);
}
return td;
}
private FilterColumnCollection GetFilterColumnsCollection(List<PropertyDescriptor> td)
{
FilterColumnCollection filterCollection = new FilterColumnCollection();
foreach (PropertyDescriptor pd in td)
{
CustomFilterColumn UFC = new CustomFilterColumn(pd.DisplayName, pd.Name,
pd.PropertyType, GetDefaultEditor(pd.PropertyType), GetClauseClass(pd.PropertyType), this);
filterCollection.Add(UFC);
}
return filterCollection;
}
static FilterColumnClauseClass GetClauseClass(Type type)
{
if (type == typeof(string))
return FilterColumnClauseClass.String;
if (type == typeof(DateTime))
return FilterColumnClauseClass.DateTime;
return FilterColumnClauseClass.Generic;
}
static RepositoryItem GetDefaultEditor(Type type)
{
if (type == typeof(DateTime))
return DefaultDateEditor;
return DefaultEditor;
}
private void OnListChanged(object sender, ListChangedEventArgs e)
{
if (e.ListChangedType == ListChangedType.PropertyDescriptorAdded ||
e.ListChangedType == ListChangedType.PropertyDescriptorDeleted ||
e.ListChangedType == ListChangedType.PropertyDescriptorChanged)
RaisePropertiesChanged();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
IBindingList oldBindingList = fDataSource as IBindingList;
if (oldBindingList != null)
oldBindingList.ListChanged -= OnListChanged;
}
base.Dispose(disposing);
}
public event EventHandler RowFilterChanged
{
add { Events.AddHandler(fRowFilterChanged, value); }
remove { Events.RemoveHandler(fRowFilterChanged, value); }
}
#region IFilteredComponent
IBoundPropertyCollection IFilteredComponent.CreateFilterColumnCollection()
{
if (Initializing) return new FilterColumnCollection();
return GetFilterColumns();
}
static readonly object fPropertiesChanged = new object();
event EventHandler IFilteredComponentBase.PropertiesChanged
{
add { Events.AddHandler(fPropertiesChanged, value); }
remove { Events.RemoveHandler(fPropertiesChanged, value); }
}
void RaisePropertiesChanged()
{
EventHandler handler = Events[fPropertiesChanged] as EventHandler;
if (handler != null)
handler(this, EventArgs.Empty);
}
CriteriaOperator IFilteredComponentBase.RowCriteria
{
get { return RowCriteria; }
set { RowCriteria = value; }
}
static readonly object fRowFilterChanged = new object();
event EventHandler IFilteredComponentBase.RowFilterChanged
{
add { RowFilterChanged += value; }
remove { RowFilterChanged -= value; }
}
void RaiseRowFilterChanged()
{
EventHandler handler = Events[fRowFilterChanged] as EventHandler;
if (handler != null)
handler(this, EventArgs.Empty);
}
#endregion
#region ISupportInitialize
bool Initializing;
void ISupportInitialize.BeginInit()
{
Initializing = true;
}
void ISupportInitialize.EndInit()
{
Initializing = false;
RaisePropertiesChanged();
}
#endregion
}
}
using System;
using System.Linq;
using System.Windows.Forms;
using System.Collections.Generic;
namespace B217847Example
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DataTableHelper.GetDataTable(dtTest);
}
private void OnFilterAdapterRowFilterChanged(object sender, EventArgs e)
{
gridView1.ActiveFilterCriteria = filterAdapter1.RowCriteria;
}
private void OnApplyFilterButtonClick(object sender, EventArgs e)
{
filterControl1.ApplyFilter();
}
}
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Windows.Forms
Namespace B217847Example
Friend NotInheritable Class Program
''' <summary>
''' The main entry point for the application.
''' </summary>
Private Sub New()
End Sub
<STAThread> _
Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1())
End Sub
End Class
End Namespace
Imports Microsoft.VisualBasic
Imports System
Imports System.Linq
Imports System.Collections
Imports System.ComponentModel
Imports System.Collections.Generic
Imports DevExpress.XtraEditors.Filtering
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.Data.Filtering.Helpers
Namespace B217847Example
Friend Class CustomFilterColumn
Inherits UnboundFilterColumn
Public Sub New(ByVal columnCaption As String, ByVal fieldName As String, ByVal columnType As Type, ByVal columnEdit As RepositoryItem, ByVal clauseClass As FilterColumnClauseClass, ByVal owner As FilterAdapter)
MyBase.New(columnCaption, fieldName, columnType, columnEdit, clauseClass)
Me.Owner = owner
End Sub
Protected ReadOnly Owner As FilterAdapter
Private ReadOnly Property DataSource() As Object
Get
Return Owner.DataSource
End Get
End Property
Private Sub GetAllUniqueValues(ByVal List As IList, ByVal op As List(Of Object))
For Each Lob As Object In List
For Each pd As PropertyDescriptor In Owner.GetProperties()
If pd.Name = FieldName Then
op.Add(pd.GetValue(Lob))
End If
Next pd
Next Lob
End Sub
Public Overrides Function CreateItemCollectionEditor() As RepositoryItem
Dim re As New FilterRepositoryItemCheckedComboBoxEdit()
If DataSource Is Nothing Then
Return re
End If
Dim List As IList
If TypeOf DataSource Is IList Then
List = TryCast(DataSource, IList)
Else
Dim Ilist As IListSource = TryCast(DataSource, IListSource)
List = Ilist.GetList()
End If
Dim op As New List(Of Object)()
GetAllUniqueValues(List, op)
For Each Value As Object In op
If Value.ToString() <> "" AndAlso re.Items(Value) Is Nothing Then
re.Items.Add(Value, Value.ToString())
End If
Next Value
Return re
End Function
Public Overrides ReadOnly Property AllowItemCollectionEditor() As Boolean
Get
Return True
End Get
End Property
End Class
End Namespace
Imports Microsoft.VisualBasic
Imports System
Imports System.Linq
Imports System.Windows.Forms
Imports System.Collections.Generic
Namespace B217847Example
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
DataTableHelper.GetDataTable(dtTest)
End Sub
Private Sub OnFilterAdapterRowFilterChanged(ByVal sender As Object, ByVal e As EventArgs) Handles filterAdapter1.RowFilterChanged
gridView1.ActiveFilterCriteria = filterAdapter1.RowCriteria
End Sub
Private Sub OnApplyFilterButtonClick(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton1.Click
filterControl1.ApplyFilter()
End Sub
End Class
End Namespace
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Data
Namespace B217847Example
Public Class DataTableHelper
Public Shared Sub GetDataTable(ByVal table As DataTable)
Dim Row1 As DataRow = table.NewRow()
Row1("Number") = 23
Row1("Name") = "Mike"
Row1("Date") = New DateTime(2012, 9, 18)
table.Rows.Add(Row1)
Dim Row2 As DataRow = table.NewRow()
Row2("Number") = 12
Row2("Name") = "Jon"
Row2("Date") = New DateTime(2012, 9, 19)
table.Rows.Add(Row2)
Dim Row3 As DataRow = table.NewRow()
Row3("Number") = 1
Row3("Name") = "Bill"
Row3("Date") = New DateTime(2012, 9, 20)
table.Rows.Add(Row3)
Dim Row4 As DataRow = table.NewRow()
Row4("Number") = 121
Row4("Name") = "Bruce"
Row4("Date") = New DateTime(2012, 9, 21)
table.Rows.Add(Row4)
Dim Row5 As DataRow = table.NewRow()
Row5("Number") = 132
Row5("Name") = "Lex"
Row5("Date") = New DateTime(2012, 9, 22)
table.Rows.Add(Row5)
End Sub
End Class
End Namespace
Imports Microsoft.VisualBasic
Imports System
Imports System.Linq
Imports System.Collections
Imports System.ComponentModel
Imports System.Collections.Generic
Imports DevExpress.XtraEditors.Filtering
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.Data.Filtering
Imports DevExpress.Data.Filtering.Helpers
Namespace B217847Example
<ToolboxItem(True)> _
Public Class FilterAdapter
Inherits Component
Implements IFilteredComponent, ISupportInitialize
<AttributeProvider(GetType(IListSource))> _
Public Property DataSource() As Object
Get
Return fDataSource
End Get
Set(ByVal value As Object)
Dim oldBindingList As IBindingList = TryCast(fDataSource, IBindingList)
If oldBindingList IsNot Nothing Then
RemoveHandler oldBindingList.ListChanged, AddressOf OnListChanged
End If
fDataSource = value
Dim newBindingList As IBindingList = TryCast(fDataSource, IBindingList)
If newBindingList IsNot Nothing Then
AddHandler newBindingList.ListChanged, AddressOf OnListChanged
End If
End Set
End Property
Private fRowCriteria As CriteriaOperator
<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Overridable Property RowCriteria() As CriteriaOperator
Get
Return fRowCriteria
End Get
Set(ByVal value As CriteriaOperator)
If ReferenceEquals(fRowCriteria, value) Then
Return
End If
fRowCriteria = value
RaiseRowFilterChanged()
End Set
End Property
Private fDataSource As Object
Private Shared DefaultEditor As New RepositoryItemTextEdit()
Private Shared DefaultDateEditor As New RepositoryItemDateEdit()
Protected Overridable Function GetFilterColumns() As FilterColumnCollection
Dim PDC As PropertyDescriptorCollection = GetProperties()
Dim td As List(Of PropertyDescriptor) = FilterPropertyDescriptionCollection(PDC)
Return GetFilterColumnsCollection(td)
End Function
Public Function GetProperties() As PropertyDescriptorCollection
Dim list As IList = TryCast(DataSource, IList)
If list Is Nothing Then
If TypeOf DataSource Is IListSource Then
list = (CType(DataSource, IListSource)).GetList()
End If
End If
If list Is Nothing Then
Return New PropertyDescriptorCollection(New PropertyDescriptor(){}, True)
End If
Dim typedList As ITypedList = TryCast(list, ITypedList)
If typedList Is Nothing Then
If list.Count > 0 Then
Return TypeDescriptor.GetProperties(list(0))
End If
Else
Return typedList.GetItemProperties(New PropertyDescriptor(){})
End If
Return New PropertyDescriptorCollection(New PropertyDescriptor(){}, True)
End Function
Private Shared Function FilterPropertyDescriptionCollection(ByVal PDC As PropertyDescriptorCollection) As List(Of PropertyDescriptor)
Dim td As New List(Of PropertyDescriptor)()
For Each pd As PropertyDescriptor In PDC
Dim op As Object = pd.PropertyType
If (Not pd.PropertyType.IsClass) OrElse (pd.PropertyType Is GetType(String)) Then
td.Add(pd)
End If
Next pd
Return td
End Function
Private Function GetFilterColumnsCollection(ByVal td As List(Of PropertyDescriptor)) As FilterColumnCollection
Dim filterCollection As New FilterColumnCollection()
For Each pd As PropertyDescriptor In td
Dim UFC As New CustomFilterColumn(pd.DisplayName, pd.Name, pd.PropertyType, GetDefaultEditor(pd.PropertyType), GetClauseClass(pd.PropertyType), Me)
filterCollection.Add(UFC)
Next pd
Return filterCollection
End Function
Private Shared Function GetClauseClass(ByVal type As Type) As FilterColumnClauseClass
If type Is GetType(String) Then
Return FilterColumnClauseClass.String
End If
If type Is GetType(DateTime) Then
Return FilterColumnClauseClass.DateTime
End If
Return FilterColumnClauseClass.Generic
End Function
Private Shared Function GetDefaultEditor(ByVal type As Type) As RepositoryItem
If type Is GetType(DateTime) Then
Return DefaultDateEditor
End If
Return DefaultEditor
End Function
Private Sub OnListChanged(ByVal sender As Object, ByVal e As ListChangedEventArgs)
If e.ListChangedType = ListChangedType.PropertyDescriptorAdded OrElse e.ListChangedType = ListChangedType.PropertyDescriptorDeleted OrElse e.ListChangedType = ListChangedType.PropertyDescriptorChanged Then
RaisePropertiesChanged()
End If
End Sub
Protected Overrides Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
Dim oldBindingList As IBindingList = TryCast(fDataSource, IBindingList)
If oldBindingList IsNot Nothing Then
RemoveHandler oldBindingList.ListChanged, AddressOf OnListChanged
End If
End If
MyBase.Dispose(disposing)
End Sub
Public Custom Event RowFilterChanged As EventHandler Implements IFilteredComponent.RowFilterChanged
AddHandler(ByVal value As EventHandler)
Events.AddHandler(fRowFilterChanged, value)
End AddHandler
RemoveHandler(ByVal value As EventHandler)
Events.RemoveHandler(fRowFilterChanged, value)
End RemoveHandler
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
End RaiseEvent
End Event
#Region "IFilteredComponent"
Private Function CreateFilterColumnCollection() As IBoundPropertyCollection Implements IFilteredComponent.CreateFilterColumnCollection
If Initializing Then
Return New FilterColumnCollection()
End If
Return GetFilterColumns()
End Function
Private Shared ReadOnly fPropertiesChanged As Object = New Object()
Private Custom Event PropertiesChanged As EventHandler Implements IFilteredComponentBase.PropertiesChanged
AddHandler(ByVal value As EventHandler)
Events.AddHandler(fPropertiesChanged, value)
End AddHandler
RemoveHandler(ByVal value As EventHandler)
Events.RemoveHandler(fPropertiesChanged, value)
End RemoveHandler
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
End RaiseEvent
End Event
Private Sub RaisePropertiesChanged()
Dim handler As EventHandler = TryCast(Events(fPropertiesChanged), EventHandler)
If handler IsNot Nothing Then
handler(Me, EventArgs.Empty)
End If
End Sub
Private Property IFilteredComponentBase_RowCriteria() As CriteriaOperator Implements IFilteredComponentBase.RowCriteria
Get
Return RowCriteria
End Get
Set(ByVal value As CriteriaOperator)
RowCriteria = value
End Set
End Property
Private Shared ReadOnly fRowFilterChanged As Object = New Object()
Private Custom Event mRowFilterChanged As EventHandler
AddHandler(ByVal value As EventHandler)
AddHandler RowFilterChanged, value
End AddHandler
RemoveHandler(ByVal value As EventHandler)
RemoveHandler RowFilterChanged, value
End RemoveHandler
RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs)
End RaiseEvent
End Event
Private Sub RaiseRowFilterChanged()
Dim handler As EventHandler = TryCast(Events(fRowFilterChanged), EventHandler)
If handler IsNot Nothing Then
handler(Me, EventArgs.Empty)
End If
End Sub
#End Region
#Region "ISupportInitialize"
Private Initializing As Boolean
Private Sub BeginInit() Implements ISupportInitialize.BeginInit
Initializing = True
End Sub
Private Sub EndInit() Implements ISupportInitialize.EndInit
Initializing = False
RaisePropertiesChanged()
End Sub
#End Region
End Class
End Namespace