This is a migrated thread and some comments may be shown as answers.

Issue: Exception while grouping columns.

1 Answer 86 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Agustin M Rodriguez, MCSD, MCPD
Top achievements
Rank 1
Agustin M Rodriguez, MCSD, MCPD asked on 21 Sep 2009, 07:54 PM
I am currently experiancing an issue when grouping columns.  I receive the following exception:

System.InvalidOperationException: No method 'Select' on type 'System.Linq.Queryable' is compatible with the supplied arguments.

I use the following code to create the grouping. The exception occurs on line 19.  I also have this issue if I drag and drop a column into the grouping header. 

 private void ExecuteGroupCommand(Object sender, ExecutedRoutedEventArgs e) {  
            telc.RadGridView grid = sender as telc.RadGridView;  
 
            if (grid != null) {  
                if (grid.CurrentCell != null) {  
                    teld.IFieldDescriptor fieldDescriptor = grid.CurrentCell.Column;  
 
                    // determine if a group descriptor for the current cell already exists  
                    teld.GroupDescriptor groupDescriptor = grid.GroupDescriptors.FirstOrDefault<teld.GroupDescriptor>(  
                        possibleDescriptor => possibleDescriptor.Member.Equals(fieldDescriptor.UniqueName));  
 
                    // if no group descriptor is found then create one and add it to the group descriptor collection.  
                    // if one exists then the grid is already grouped by the selected cell so there is no need to   
                    // do it again.  
                    if (groupDescriptor == null) {  
                        groupDescriptor = new teld.GroupDescriptor();  
                        groupDescriptor.Member = fieldDescriptor.UniqueName;  
                        groupDescriptor.SortDirection = System.ComponentModel.ListSortDirection.Ascending;  
                        grid.GroupDescriptors.Add(groupDescriptor);  
                    }  
                }  
            }  
 
            e.Handled = true;  
        } 

[Exception Details]

System.Reflection.TargetInvocationException was unhandled
  Message="Exception has been thrown by the target of an invocation."
  Source="mscorlib"
  StackTrace:
       at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Delegate.DynamicInvokeImpl(Object[] args)
       at System.Windows.RoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at Telerik.Windows.Controls.GridView.GridViewItemsControl.RaiseGroupingEvent(IColumnInfo draggedCell, Int32 index, GroupingEventAction groupingEventAction)
       at Telerik.Windows.Controls.GridView.GridViewGroupPanel.Telerik.Windows.Controls.GridView.DragDrop.IDropTarget.Drop(UIElement draggedElement)
       at Telerik.Windows.Controls.GridView.DragDrop.DragDropManager.EndDrag(Boolean drop)
       at Telerik.Windows.Controls.GridView.DragDrop.WpfDragDropManager.EndDrag(Boolean drop)
       at Telerik.Windows.Controls.GridView.DragDrop.DragDropManager.ProcessMouseLeftButtonUp()
       at Telerik.Windows.Controls.GridView.GridViewHeaderCell.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at Iti.Ccs.Shell.App.Main() in C:\Users\arodriguez\Documents\ITI.CCS\Trunk\Source\Iti.Ccs.Shell\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.InvalidOperationException
       Message="No method 'Select' on type 'System.Linq.Queryable' is compatible with the supplied arguments."
       Source="System.Core"
       StackTrace:
            at System.Linq.Expressions.Expression.FindMethod(Type type, String methodName, Type[] typeArgs, Expression[] args, BindingFlags flags)
            at System.Linq.Expressions.Expression.Call(Type type, String methodName, Type[] typeArguments, Expression[] arguments)
            at Telerik.Windows.Data.QueryableExtensions.CallQueryableMethod(IQueryable source, String methodName, LambdaExpression selector)
            at Telerik.Windows.Data.QueryableExtensions.Select(IQueryable source, LambdaExpression selector)
            at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilderBase.CreateQuery()
            at Telerik.Windows.Data.Expressions.GroupDescriptorCollectionExpressionBuilder.CreateQuery()
            at Telerik.Windows.Data.QueryableExtensions.GroupBy(IQueryable source, GroupDescriptorCollection groupDescriptors)
            at Telerik.Windows.Data.QueryableCollectionView.CreateView()
            at Telerik.Windows.Data.QueryableCollectionView.get_QueryableView()
            at Telerik.Windows.Data.QueryableCollectionView.CreateInternalList()
            at Telerik.Windows.Data.QueryableCollectionView.get_InternalList()
            at Telerik.Windows.Data.QueryableCollectionView.GetEnumerator()
            at Telerik.Windows.Data.RecordFactory.<CreateRecordsForGroupRecord>d__0.MoveNext()
            at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
            at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
            at Telerik.Windows.Controls.GridView.GridViewDataControl.PopulateRecords()
            at Telerik.Windows.Controls.GridView.GridViewDataControl.LoadData()
            at Telerik.Windows.Controls.GridView.GridViewDataControl.OnCollectionViewCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
            at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
            at Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
            at Telerik.Windows.Data.QueryableCollectionView.RefreshAndRaiseCollectionChanged(NotifyCollectionChangedEventArgs args)
            at Telerik.Windows.Data.QueryableCollectionView.Refresh()
            at Telerik.Windows.Data.QueryableCollectionView.EndDefer()
            at Telerik.Windows.Data.QueryableCollectionView.DeferHelper.Dispose()
            at Telerik.Windows.Controls.GridView.GridViewDataControl.PerformGrouping(String member, Object displayContent, Nullable`1 insertionIndex)
            at Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClass2a.<GroupingRequested>b__29()
            at Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(FrameworkElement frameworkElement, Action action)
            at Telerik.Windows.Controls.GridView.GridViewDataControl.GroupingRequested(Object origin, GroupingRequestedEventArgs e)
       InnerException:


1 Answer, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 23 Sep 2009, 01:33 PM
Hello Agustin,

The problem is that the GroupDescriptor you are creating has its Member property set to null. In your code when you are using fieldDescriptor.UniqueName it returns null. I suppose you have set DataMemberBinding for each of your columns in XAML.

What I can suggest you is to cast the current cell's column to IDataFieldDescriptor and use its Binding property like this:
IDataFieldDescriptor fieldDescriptor = this.GridView.CurrentCell.Column as IDataFieldDescriptor; 
 
// determine if a group descriptor for the current cell already exists   
if (fieldDescriptor != null
    GroupDescriptor groupDescriptor = this.GridView.GroupDescriptors.FirstOrDefault( 
        possibleDescriptor => possibleDescriptor.Member.Equals(fieldDescriptor.UniqueName)); 
 
    // if no group descriptor is found then create one and add it to the group descriptor collection.   
    // if one exists then the grid is already grouped by the selected cell so there is no need to    
    // do it again.   
    if (groupDescriptor == null
    { 
        groupDescriptor = new GroupDescriptor(); 
        groupDescriptor.Member = fieldDescriptor.DataMemberBinding.Path.Path; 
        groupDescriptor.SortDirection = ListSortDirection.Ascending; 
        this.GridView.GroupDescriptors.Add(groupDescriptor); 
    } 

Hope this helps.

Best wishes,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Agustin M Rodriguez, MCSD, MCPD
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Share this question
or