Click here to Skip to main content
13,400,768 members (39,316 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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?

Posted 12-Feb-13 18:11pm
Guirec Le Bars 12-Feb-13 23:14pm
Did you try with '==' instead of '=' ?
SuperSh33p 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 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 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 13-Feb-13 0:57am
ok so don't transform it to a string represnetation but to a Decimal one.
SuperSh33p 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 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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You do it like this:[^]

dt.DefaultView.RowFilter = "CONVERT([Money Column], System.String) = '12345.67'"
Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180218.2 | Last Updated 7 May 2015
Copyright © CodeProject, 1999-2018
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