I use to inherits this class for a special feature for filtering a "flagable enum"
Since it is cannot be inherits anymore, I try ro create my filter again
big lines:
1. standard "disctinct values"
2. an enum that have multiple state are included in filter even if the values is not "EQUALS" but contains...
My problem reside on the "yellow hilighted line."
Braking changes links : http://www.telerik.com/community/forums/wpf/gridview/known-issues-and-breaking-changes---radgridview.aspx
complete doc : Doc
My code: (not original, but cleaned for reading perpose..)
class MaxEnumFlagsDescriptor : FilterDescriptor
{
private FilterDescriptor<MaintenanceBoxDataDataTableRow> Filter;
private string dataMember;
/// <summary>
/// Initializes a new instance of the <see cref="MaxEnumFlagsDescriptor"/> class.
/// </summary>
/// <param name="control">The column.</param>
/// <param name="dataMember">The data member.</param>
/// <param name="enumType">Type of the enum.</param>
public MaxEnumFlagsDescriptor(MaxFilteringControl control, string dataMember, Type enumType)
{
if (dataMember.StartsWith("["))
dataMember = dataMember.RemoveFromStart(1).RemoveFromEnd(1);
this.Control = control;
this.Column = control.GridColumn as GridViewBoundColumnBase;
this.dataMember = dataMember;
this.EnumType = enumType;
Filter = new FilterDescriptor<MaintenanceBoxDataDataTableRow>();
Filter.FilteringExpression = (e) => (Check(e));
}
/// <summary>
/// Creates the filter expression.
/// </summary>
/// <param name="instance">The instance.</param>
/// <returns></returns>
public override System.Linq.Expressions.Expression CreateFilterExpression(System.Linq.Expressions.Expression instance)
{
return Filter.CreateFilterExpression(instance);
}
private bool Check(DataRow row)
{
if (this.DistinctValue == null || !this.Control.IsActive)
return true;
var desc = this.DistinctValue; // this was available in the ColumnFilterDescriptor. originaly
// in the class (so how to get it..)
// HOW TO GET THE CHECKED VALUES OF THE DISTINCT VALUE LIST
if (!desc.Any())
return true;
Debug.Assert(row != null, "Should have found a Row");
if (row != null)
{
var inf = row[this.dataMember];
if (inf == DBNull.Value)
inf = null;
if (inf == null)
return desc.Any(c => c == null);
else
{
var enumType = this.EnumType;
try
{
var val = Enum.ToObject(enumType, inf).ToString();
return desc.Any(c => IsInclude(c, val, enumType));
}
catch (System.Exception ex)
{
// In case of old value
Debug.Fail(ex.Message);
return false;
}
}
}
return true;
}
private static bool IsInclude(object value, string data, Type enumType)
{
var val = Enum.ToObject(enumType, value).ToString();
return data.IndexOf(val) >= 0;
}
}