I try to create a custom aggregate function.
I get this exception.
"No generic method 'SimCandidateCount' on type 'GenerateFieldEmulator.SimCandidateCounter' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic."
Can you either spot what is wrong or tell me how to find out what the failing overload resolution information is?
xaml:
<telerik:GridViewColumn.AggregateFunctions>
<local:SimCount SourceField="SimPossible" SourceFieldType="{x:Type System:Boolean}" Caption="Candidate Modules : " />
</telerik:GridViewColumn.AggregateFunctions>
The SimCount class is here.
public
class SimCount : Telerik.Windows.Data.EnumerableSelectorAggregateFunction
{
protected override string AggregateMethodName
{
get { return "SimCandidateCount"; }
}
protected override Type ExtensionMethodsType
{
get
{
return typeof(SimCandidateCounter);
}
}
}
public static class SimCandidateCounter
{
public static int SimCandidateCount<TSource>(IEnumerable<TSource> source,Func<TSource,bool> selector )
{
return source.Select(selector).Count(b => b);
}
}
6 Answers, 1 is accepted
Can you please send me the implementation of the objects you use in the ItemsSource for RadGridView.
I will gather a small sample for you with your data objects.
Kind regards,
Pavel Pavlov
the Telerik team
Sorry for taking a while in responding.
The data objects have some dependencies due to the type of private fields..
If you could just show me on a simple data object.
enum gender{male,female};
class person
{
string name {get;set;}
gender sex {get;set;}
}
and then just show a custom aggregate function that display number of males, that would be good.
Or are you saying that you expect my code to work, and that we should be debugging it?
Please find the project attached.
Regards,
Pavel Pavlov
the Telerik team
Problem is that I have the grid within a datatemplate. AFAIK, I cannot do "RadGridView1.Columns[0]... in the constructor"
This is becoming a general WPF question rather than specific to the RadGridView control, but still.
Can you please show how you would go about creating this from markup? Is there any "WPF" way of dealing with accessing in xaml something created from the code behind?
Should I create the AggregateFunction in the code behind and then add it to the Resources collection of the window? But this would be difficult since both the window creation and resource consumption happen inside "initializecomponents"? I cannot "wedge" anything in between the two.
Maybe I can create an empty AggregateFunction in the Resources section of XAML and then retrieve it by name from the code behind and set its AggregationExpression property after InitializeComponents?
Or would I need to set it as a dynamic resource and then assign an entirely new AggregationFunction?
The best I think of for the moment is x:Static. But this will only help me when I don't need instance members, even though that is the case for the moment.
There are many possible approaches to solve the case. Lets start with an easier one :
In your data template you can subscribe to the DataLoaded event of RadGridView. Then in the event handler you may perform any additional initialization e.g. adding the aggregate function.
Regards,
Pavel Pavlov
the Telerik team
In your last example:
If you move the aggregatefunction setup to an eventhandler fired from the DataLoaded event and then.
* Start the application.
* Drag a column to the grouping area.
* Then click the "x" on it to remove the grouping.
..... causes exception.
But using "Loaded" appears to work just fine. Thank you.
Tormod