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

[Solved] GridView aggrigate SumFunction

3 Answers 188 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
preeti
Top achievements
Rank 1
preeti asked on 31 Dec 2010, 07:02 AM
I am using GridView aggrigates SumFunction.
Since i have large number of records it returns me a very large value .
kindly check the attached file.
How do i eliminate this.

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 03 Jan 2011, 08:18 AM
Hi preeti,

There are a couple of options here - you may create a custom aggregate function that will return the result you want. For further reference you may take a look at our demos. Another possible approach may be to work with the ResultFormatString property as demonstrated in here.
  

Regards,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
preeti
Top achievements
Rank 1
answered on 03 Jan 2011, 10:44 AM
Hi Maya,

i tried using custom aggrigate function. but it pops up the following error.
No generic method 'StdDev' on type 'FIT.Sales.InfoAggreGator.CommonControls.ConversationGrid.View.Statistics' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
Can you tell me what is wrong? i am pasteing the code below.


<telGrid:GridViewDataColumn Header="Rev Net YTD($)" IsGroupable="False"  TextAlignment="Right"  IsReadOnly="True" IsFilterable="True" DataMemberBinding="{Binding YTDREVENUENET,Converter={StaticResource textFormatConverter},ConverterParameter=\{0:n\}}" >
   <telGrid:GridViewDataColumn.AggregateFunctions>
              <local:StandardDeviationFunction SourceField="YTDREVENUENET" Caption="Net Rev YTD($):" ResultFormatString="{}{0:G}" />
    </telGrid:GridViewDataColumn.AggregateFunctions>
</telGrid:GridViewDataColumn>
using System;
using Telerik.Windows.Data;
  
namespace FIT.Sales.InfoAggreGator.CommonControls.ConversationGrid.View
{
    public class StandardDeviationFunction : EnumerableSelectorAggregateFunction
    {
         
  
        protected override string AggregateMethodName
        {
            get
            {
                return "StdDev";
            }
        }
  
        protected override Type ExtensionMethodsType
        {
            get
            {
                return typeof(Statistics);
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
  
namespace FIT.Sales.InfoAggreGator.CommonControls.ConversationGrid.View
{
    public static class Statistics
    {
        public static double StdDev<TSource>(IEnumerable<TSource> source, Func<TSource, float> selector)
        {
            int itemCount = source.Count();
            if (itemCount > 1)
            {
                IEnumerable<float> values = from i in source select Convert.ToSingle(selector(i));
                float sum = Sum(values);
                return sum;
            }
            return 0;
        }
  
        private static float Sum(IEnumerable<float> values)
        {
            float sum = 0;
            foreach (float item in values)
            {
                sum += item;
            }
            return sum;
        }
    }
}

0
Maya
Telerik team
answered on 03 Jan 2011, 01:24 PM
Hi preeti,

Please refer again to other forum thread you participated in and do try to follow up the suggestions made. You need to make sure that the types defined are adequate to your data.  

All the best,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
preeti
Top achievements
Rank 1
Answers by
Maya
Telerik team
preeti
Top achievements
Rank 1
Share this question
or