Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ VB.NET
I have a custom 'Money' type that I display in a DataGrid. The column in the datatable that I bind to the DataGrid.DataSource is therefore defined as type Money. I want to be able to filter the contents of the DataGrid using DataTable.DefaultView.RowFilter using code like the following:
 
dt.DefaultView.RowFilter = "[Money Column] = 12345.67"
 
However whenever this code executes I'm getting the following error:
 
System.Data.EvaluateException occurred
Message=Cannot perform '=' operation on NAB.WM.CIMS.BusinessObjects.Money and System.Decimal.

 
I thought I could fix this simply by adding a new "=" operator to my Money class which compares Money with Decimal, but this operator is being completely ignored.
 
The code that appears to be executing the compare is System.Data.BinaryNode.EvalBinaryOp.
Is there any way I can extend this class/method to allow me to use the Money type, or is there another solution that I'm missing?
 
Thanks!
Posted 12-Feb-13 18:11pm
Comments
Guirec Le Bars at 12-Feb-13 23:14pm
   
Did you try with '==' instead of '=' ?
SuperSh33p at 12-Feb-13 23:55pm
   
Sorry, it's not clear but I'm currently working in VB.NET, so it's all '='.
Guirec Le Bars at 13-Feb-13 0:07am
   
ah ok, sorry.
To solve your issue I suggest you add an additional property to your source object. This new property (let's say you call it MoneycolumConverted) would be the ToString() value (or whatever string representation...) of your Money property then you could write your filter like :
 
dt.DefaultView.RowFilter = "MoneycolumConverted = 12345.67"
 
should work...
SuperSh33p at 13-Feb-13 0:54am
   
Good suggestion.
Unfortunately, I don't think this would work for some of the other filters that I'd ultimately like to add, specifically > (greater than) and < (less than):
"987.65" > "1234567.89" = True
 
I figured that if I could get equality working, then other operators would be relatively easy.
Guirec Le Bars at 13-Feb-13 0:57am
   
ok so don't transform it to a string represnetation but to a Decimal one.
SuperSh33p at 14-Feb-13 20:20pm
   
Ha! Sorry, I should have thought of that. Good one.
This certainly represents a nice work around, but I'd like to see if an integrated solution to adding custom types to the filter emerges.
PIEBALDconsult at 12-Feb-13 23:41pm
   
You're very limited in what you can do in a RowFilter. This may be one of the things you can't do.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I guess you have a working solution now so I add some text here so that your question does not appear as "not answered" anymore
 
As mentioned by PIEBALDconsult you are very limited to what you can do in a RowFilter but there is an additional thing you can try : if you have the ability to modify the NAB.WM.CIMS.BusinessObjects.Money class then you can try to implement custom conversion with Decimal and String and also override the = operator. Might work as well. But the simplest solution remains the one I gave you above.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100