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

Filter a column with custom type - "No coercion operator is defined between types […]"

2 Answers 878 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
Filip
Top achievements
Rank 1
Filip asked on 04 Jul 2014, 05:00 PM
Hello!

I'm trying to enable filtering on a column which is bound to a property of a object whose structure is something like this:

Portfolios:
   - PortfolioInformationExtended:
      - String
   - PortfolioInformationExtended:
      - String
   - PortfolioInformationExtended:
      - String

PortfolioInformationExtended is a sub-class of PortfolioInformation.

I have tried to be diligent in my reading of the documentation and have implemented IComparable<PortfolioInfoExtended>, IEquatable<PortfolioInfoExtended>, IComparable<String>, IEquatable<String> in the PortfolioInfoExtended-class as per instructions here on the forum and in the documentation. 

I have successfully gotten the column to group (when I drag the header) but when I try to filter it I get the error message:
"No coercion operator is defined between types 'System.Collections.ObjectModel.ObservableCollection`1[MarketValueWeb.RateServiceReference.PortfolioInfo]' and MIQ.SilverlightExstenstion.Nordkap.PortfolioInfoExtended'.

The DataType property of this column is set to PortfolioInformation, and since the grouping works the operators seem to be working.

I am a bit confused by this and is wondering if I have missed some obvious step, or if everything seem to be in order. Any suggestions on how to proceed?

Thanks in advance!








2 Answers, 1 is accepted

Sort by
0
Filip
Top achievements
Rank 1
answered on 07 Jul 2014, 07:35 AM
Ok, I have investigated this further and realised that the problem lies in the fact that the itemSource the column is bound to is a collection of my objects and that the search function returns a single object. 

If I implement a implicit operator between my class and my list, it seems to work. However, I don't get any "suggestions" (where you normally can click boxes). I have implemented ToString() on my object, but that does not seem to help.
0
Dimitrina
Telerik team
answered on 07 Jul 2014, 10:23 AM
Hello,

This error says that you try to use a value that is of diffident type than the column's values. If the actual type of the property is a ObservableCollection`1[MarketValueWeb.RateServiceReference.PortfolioInfo]' , then it cannot be treated as a PortfolioInfoExtended оr а string, because comparisons have to be made and those two types don't compare to each other out-of-the-box.  

You should ensure the DataType of the bound data is the same as the DataType of the Value you set. 

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
DataFilter
Asked by
Filip
Top achievements
Rank 1
Answers by
Filip
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or