AggregateFunction not working

4 posts, 0 answers
  1. Marco
    Marco avatar
    23 posts
    Member since:
    Apr 2009

    Posted 03 Nov 2009 Link to this post

    Hi,
    I have a grid with auto-generated columns, which allows the user to group by any column.  I want to show the number of records for whichever column the user has groups.

    In added an event handler for the Grouping event and put this code, but I got an exception (shown below):

    private void WipGrid_Grouping(object sender, Telerik.Windows.Controls.GridView.GridView.GridViewGroupingEventArgs e)  
    {  
       var countFunction = new CountFunction("count", e.GroupDescriptor.Member, "Total records: ");  
       e.GroupDescriptor.AggregateFunctions.Add(countFunction);  

    Then, I realized the constructor with parameters is obsolete, so I tried the following code, but I got the same error
    private void WipGrid_Grouping(object sender, Telerik.Windows.Controls.GridView.GridView.GridViewGroupingEventArgs e) 
            { 
                var countFunction = new CountFunction(); 
                countFunction.Caption = "Total records: "
                countFunction.FunctionName = "Count"
                e.GroupDescriptor.AggregateFunctions.Add(countFunction); 
            } 

    What am I missing?   How can I implement this feature?

    Exception:
    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 Intel.Cqn.Luminis.LuminisEXE.App.Main() in C:\Projects\Source\Luminis\DEV\Luminis\Intel.Cqn.Luminis.LuminisEXE\obj\Debug\App.g.cs:line 0
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
           at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
           at System.Activator.CreateInstance(ActivationContext activationContext)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
           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.ArgumentException
           Message="An item with the same key has already been added."
           Source="mscorlib"
           StackTrace:
                at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
                at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
                at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
                at Telerik.Windows.Data.Dynamic.ClassFactory.GetDynamicClass(IEnumerable`1 properties)
                at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.CreateProjectionNewExpression(IEnumerable`1 propertyValuesExpressions)
                at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.CreateProjectionInitExpression()
                at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.CreateAggregateFunctionsProjectionMemberBinding()
                at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.<CreateMemberBindings>d__0.MoveNext()
                at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
                at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
                at System.Linq.Expressions.ReadOnlyCollectionExtensions.ToReadOnlyCollection[T](IEnumerable`1 sequence)
                at System.Linq.Expressions.Expression.MemberInit(NewExpression newExpression, IEnumerable`1 bindings)
                at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.CreateSelectBodyExpression()
                at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.CreateSelectExpression()
                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.get_ItemCount()
                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:



    Regards,
    Marco


  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 04 Nov 2009 Link to this post

    Hello Marco,

    The official 2009 Q3 Release has shipped today. I have tested with it and everything seems to work fine. Could you please upgrade and check whether everything is alright?

    Drop us a line in case you are still experiencing problems.

    Best wishes,
    Ross
    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. hmn5792
    hmn5792 avatar
    2 posts
    Member since:
    Jul 2006

    Posted 04 Nov 2009 Link to this post

    Hi,
    The original issue was solved, but upgrading to 2009.Q3 caused several errors in my application.  After fixing some of them, I found one that is giving me a headache.
    The below code doesn't work anymore.  The intention is pretty obvious, I want to display a comboBox in a column in runtime with the provided list.
    var col = myGrid.Columns[2]; 
    var comboBoxEditor = new ComboBoxEditorSettings(); 
    comboBoxEditor.ItemsSource = GetCountries(); 
    ((GridViewDataColumn)col).EditorSettings = comboBoxEditorSettings
     

    I'd appreciate if you can give me some direction on this one.

    One last comment, I've gone through some upgrades, and everytime I do it, it generates issues in my code, which is sort of understandable because of the changes in methods and properties, but it would be very helpful to all the customers to have documentation that indicates how to solve these issues.  Not only say that one property or method is obsolete (in your release notes), but give some idea on how to make it work with the new version.

    Regards,
    Marco
  5. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 09 Nov 2009 Link to this post

    Hi Marco,

    Sorry for the inconvenience caused.
    Straight onto your problem. Your code should look something like this:

    var col = myGrid.Columns[2] as GridViewComboBoxColumn;
    col.ItemsSource = GetCountries();

    and of course in xaml or wherever you create this column just create GridViewComboBoxColumn instead of GridViewDataColumn.

    Regards,
    Nedyalko Nikolov
    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.
Back to Top