Hi
I used binding DataTable to GridView...
flowing code:
and then i used CustomAggregateFunction ..
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??
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??