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

How to use CustomAggreageFunction???

0 Answers 19 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Guntae Park
Top achievements
Rank 1
Guntae Park asked on 25 Jan 2012, 05:56 AM
Hi 

I used binding DataTable to GridView...


flowing code:
DataTable table = new DataTable("Data Table");
 
DataColumn column;
DataRow row;
 
column = new DataColumn();
column.DataType = typeof(DateTime);
column.ColumnName = "Time";
column.ReadOnly = true;
column.Unique = true;
table.Columns.Add(column);
 
column = new DataColumn();
column.DataType = typeof(double);
column.ColumnName = "A";
column.ReadOnly = true;
column.Unique = false;
table.Columns.Add(column);
 
column = new DataColumn();
column.DataType = typeof(double);
column.ColumnName = "B";
column.ReadOnly = true;
column.Unique = false;
table.Columns.Add(column);
 
// Create three new DataRow objects and add
// them to the DataTable
for (int i = 0; i <= 20; i++)
{
    row = table.NewRow();
    row["Time"] = DateTime.Now.AddSeconds(i);
    row["A"] = random.NextDouble() * 100;
    row["B"] = random.NextDouble() * 50;
 
    table.Rows.Add(row);
}
 
gridView.ItemsSource = table;

and then i used CustomAggregateFunction .. 

public static class Statistics
{
    public static double StdDev<TSource>(DataTable source, Func<TSource, double> selector)
    {
        int itemCount = source.Rows.Count();
        if (itemCount > 1)
        {
            IEnumerable<double> values = from i in source select Convert.ToDouble(selector(i));
 
            double sum = SumAvg(values);
 
            return Math.Sqrt(sum / (itemCount - 1));
        }
 
        return 0;
    }
 
    private static double SumAvg(IEnumerable<double> values)
    {
        double average = values.Average();
        double sum = 0;
 
        foreach (double item in values)
        {
            sum += Math.Pow(item - average, 2);
        }
 
        return sum;
    }
}

public class StandardDeviationFunction : EnumerableSelectorAggregateFunction
{
    protected override string AggregateMethodName
    {
        get
        {
            return "StdDev";
        }
    }
 
    protected override Type ExtensionMethodsType
    {
        get
        {
            return typeof(Statistics);
        }
    }
}

but this function occur exception :
{"No generic method 'StdDev' on type 'NS.Client.Models.Controls.Statistics' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. "}

what's wrong??

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Guntae Park
Top achievements
Rank 1
Share this question
or