Filtering Exception

1 posts, 0 answers
  1. Xinfeng
    Xinfeng avatar
    15 posts
    Member since:
    Jul 2011

    Posted 01 Sep 2011 Link to this post

    We got the following exception sometime when filtering the GridView:

    Failed to compare two elements in the array.
       at System.Collections.Generic.ArraySortHelper`1.BinarySearch(T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
       at System.Array.BinarySearch[T](T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
       at System.Collections.Generic.List`1.BinarySearch(Int32 index, Int32 count, T item, IComparer`1 comparer)
       at Telerik.Windows.Data.KeyedCollection.IndexOf(Object value)
       at Telerik.Windows.Data.QueryableCollectionView.InternalIndexOf(Object item)
       at Telerik.Windows.Data.QueryableCollectionView.IndexOf(Object item)
       at Telerik.Windows.Data.QueryableCollectionView.Contains(Object item)
       at Telerik.Windows.Data.DataItemCollection.Contains(Object value)
       at Telerik.Windows.Controls.GridView.GridViewDataControl.CanActivateRowExecute(Object sender, CanExecuteRoutedEventArgs e)
       at Telerik.Windows.Controls.CommandBinding.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)
       at Telerik.Windows.Controls.CommandManager.FindCommandBinding(CommandBindingCollection commandBindings, Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
       at Telerik.Windows.Controls.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
       at Telerik.Windows.Controls.CommandManager.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)
       at Telerik.Windows.Controls.CanExecuteRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object target)
       at Telerik.Windows.RadRoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at Telerik.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RadRoutedEventArgs routedEventArgs)
       at Telerik.Windows.EventRoute.InvokeHandlersImpl(Object source, RadRoutedEventArgs args, Boolean raisedAgain)
       at Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)
       at Telerik.Windows.Controls.RoutedCommand.CanExecute(Object parameter, UIElement target)
       at Telerik.Windows.Controls.GridView.GridViewDataControl.ExecutePendingCommand()
       at Telerik.Windows.Controls.GridView.GridViewDataControl.OnKeyDown(KeyEventArgs e)
       at System.Windows.Controls.Control.OnKeyDown(Control ctrl, EventArgs e)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)---
    Failed to compare two elements in the array.
       at Telerik.Windows.Data.FuncExtensions.<>c__DisplayClass1`2.<ToUntypedFunc>b__0(Object item)
       at Telerik.Windows.Data.FunctionComparer.Compare(Object x, Object y)
       at System.Collections.Generic.ArraySortHelper`1.InternalBinarySearch(T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
       at System.Collections.Generic.ArraySortHelper`1.BinarySearch(T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)---

    The code related to the filter is as following:

    private
     readonly PredicateFilterDescriptor _quickFilter;

     public void Filter()
     {
                if( Control.FilterDescriptors.Count == 0 )
                    Control.FilterDescriptors.Add(_quickFilter);
     
                _quickFilter.FilterValue = QuickFilterValue;
     }        
    
    
    public class PredicateFilterDescriptor : FilterDescriptorBase
     {
            private readonly Func<object,string,bool> _predicate;
     
            public string FilterValue { getset; }
     
            public PredicateFilterDescriptor(Func<object,string,bool> predicate) { _predicate = predicate; }
     
            protected override System.Linq.Expressions.Expression CreateFilterExpression(ParameterExpression parameterExpression)
            {
                if (string.IsNullOrEmpty(FilterValue))
                    return System.Linq.Expressions.Expression.Constant(true);
     
                return System.Linq.Expressions.Expression.Invoke(
                    System.Linq.Expressions.Expression.Constant(_predicate), 
                    parameterExpression,
                    System.Linq.Expressions.Expression.Constant(FilterValue));
            }
      }
    
    Thanks a lot!
    
Back to Top