I am getting this error when adding aggregate culumn at run time;
No generic method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
private void SearchGrid_AutoGeneratingColumn(object sender,
Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
{
if (string.IsNullOrEmpty(ReportWizardViewModel.ReportDefinition.Summary)) return;
var fields = ReportWizardViewModel.ReportDefinition.Summary.Split(new char[] { ',' });
var dataColumn = e.Column as GridViewDataColumn;
if (dataColumn != null)
{
var columnName = dataColumn.Header.ToString();
var fieldDef = fields.FirstOrDefault(w => w.StartsWith(columnName));
if (fieldDef != null)
{
var pref = fieldDef.Replace(columnName + "-", "");
dataColumn.DataMemberBinding.StringFormat = "{0:" + pref + "}";
dataColumn.AggregateFunctions.Add(new SumFunction()
{
Caption = columnName + " :",
SourceField = columnName,
ResultFormatString = "{}{0:c2}",
SourceFieldType = typeof(decimal)
});
}
}
}
10 Answers, 1 is accepted
Can you check if you have numeric property with such name in your objects bound to grid?
All the best,Vlad
the Telerik team
I am not sure, I am using a dynamic solution one of you guys posted. Usinng Wcf service generate DataSet to MyDataRow
here is code;
//client
var client = new ReportServiceClient();
client.GetDataCompleted += (s, e) =>
{
if (e.Error != null)
{
var error = e.Error.Message;
RadWindow.Alert(error);
return;
}
Data = new ObservableCollection<
MyDataRow
>(from i in e.Result
select
new MyDataRow(i));
RaisePropertyChanged("Data");
};
client.GetDataAsync(ReportDefinition.Sql);
where MyDataRow
public class MyDataRow : DynamicObject, INotifyPropertyChanged
{
IDictionary<
string
, object> data;
public MyDataRow()
{
data = new Dictionary<
string
, object>();
}
public MyDataRow(IDictionary<
string
, object> source)
{
data = source;
}
public override IEnumerable<
string
> GetDynamicMemberNames()
{
return data.Keys;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = this[binder.Name];
return true;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
this[binder.Name] = value;
return true;
}
public object this[string columnName]
{
get
{
if (data.ContainsKey(columnName))
{
return data[columnName];
}
return null;
}
set
{
if (!data.ContainsKey(columnName))
{
data.Add(columnName, value);
OnPropertyChanged(columnName);
}
else
{
if (data[columnName] != value)
{
data[columnName] = value;
OnPropertyChanged(columnName);
}
}
}
}
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
Can you post the property declaration?
Kind regards,Vlad
the Telerik team
Implemented based on this http://blogs.telerik.com/blogs/posts/11-09-28/dynamic-binding-for-your-silverlight-applications.aspx
I'm afraid that standard Sum will not work for dynamics. You will need to create custom aggregate function - please check our demos for more info about various custom aggregates.
Regards,Vlad
the Telerik team
Thanks,
Getting this now, Do not know how to fix this
No generic method 'MySum' on type 'HiscoBudget.Controls.CustomSumCalc' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
client code changes
dataColumn.AggregateFunctions.Add(new CustomSum()
{
Caption = columnName + " :",
SourceField = columnName,
ResultFormatString = "{}{0:c2}"
});
public class CustomSum : EnumerableSelectorAggregateFunction
{
protected override string AggregateMethodName
{
get { return "MySum"; }
}
protected override Type ExtensionMethodsType
{
get { return typeof(CustomSumCalc); }
}
}
public static class CustomSumCalc
{
public static double MySum<
TSource
>(IEnumerable<
TSource
> source, Func<
TSource
, double> selector)
{
int itemCount = source.Count();
if (itemCount > 1)
{
IEnumerable<
double
> values = from i in source select Convert.ToDouble(selector(i));
return values.Sum();
}
return 0;
}
}
No generic method 'MySum' on type 'HiscoBudget.Controls.CustomSumCalc' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
If the custom aggregates do not work in your case, then I would recommend you to try the approach suggested in this forum thread.
Regards,Didie
the Telerik team