Hi..
I'm trying to implement a Custom Filter for a computed column in RadGridView.
The computed column is simply a Year-range eg: "2010-2015" - i want to filter all rows that contains a given year, eg: 2013.
Tthe computed column is using this type, where i've added the IEquitable interface.
public class YearRange : IEquatable<int>
{
public int FromYear { get; set; }
public int ToYear { get; set; }
public override string ToString()
{
return FromYear + "-" + ToYear;
}
public bool Equals(int other)
{
return FromYear >= other && other <= ToYear;
}
}
The CustomGridFilter is implemented like this, where i've copied the telerik sample and modified it a bit.
public partial class CustomGridFilter : UserControl, IFilteringControl
{
private GridViewBoundColumnBase column;
private CompositeFilterDescriptor compositeFilter;
private FilterDescriptor rangeFilter;
#region IsActive DependencyProperty
public bool IsActive
{
get { return (bool)GetValue(IsActiveProperty); }
set { SetValue(IsActiveProperty, value); }
}
public static readonly DependencyProperty IsActiveProperty =
DependencyProperty.Register(
"IsActive",
typeof(bool),
typeof(CustomGridFilter),
new PropertyMetadata(false));
#endregion
#region Aargang DependencyProperty
public int Aargang
{
get { return (int)GetValue(AargangProperty); }
set { SetValue(AargangProperty, value); }
}
public static readonly DependencyProperty AargangProperty =
DependencyProperty.Register(
"Aargang",
typeof(int),
typeof(CustomGridFilter),
new PropertyMetadata(0)
);
#endregion
public CustomGridFilter()
{
InitializeComponent();
DataContext = this;
}
public void Prepare(Telerik.Windows.Controls.GridViewColumn column)
{
this.column = column as GridViewBoundColumnBase;
if (this.column == null)
{
return;
}
if (compositeFilter == null)
{
CreateFilters();
}
}
private void CreateFilters()
{
string dataMember = column.DataMemberBinding.Path.Path;
compositeFilter = new CompositeFilterDescriptor();
rangeFilter = new FilterDescriptor(dataMember, FilterOperator.IsEqualTo, null);
compositeFilter.FilterDescriptors.Add(rangeFilter);
}
private void OnFilter(object sender, RoutedEventArgs e)
{
rangeFilter.Value = Aargang;
if (!column.DataControl.FilterDescriptors.Contains(compositeFilter))
{
column.DataControl.FilterDescriptors.Add(compositeFilter);
}
IsActive = true;
var popup = this.ParentOfType<System.Windows.Controls.Primitives.Popup>();
if (popup != null)
{
popup.IsOpen = false;
}
}
private void OnClear(object sender, RoutedEventArgs e)
{
if (column.DataControl.FilterDescriptors.Contains(compositeFilter))
{
column.DataControl.FilterDescriptors.Remove(compositeFilter);
}
Aargang = 0;
IsActive = false;
var popup = this.ParentOfType<System.Windows.Controls.Primitives.Popup>();
if (popup != null)
{
popup.IsOpen = false;
}
}
}
The XAML is simply a textbox bound to the Aargang DependencyProperty which is functioning correctly considering the error message.
My assumption is that IEquiatable<int> is supposed to execute the FilterOperator.IsEqualTo comparison ?
Why does it fail ?
EDIT:
Debugging the "solution" from this question, https://www.telerik.com/forums/problem-with-custom-filter-with-custom-type - i've found that IEquatable is used for the GetDistinctValues operation while the ACTUAL comparison uses standard override Equals operator ... FFS...