MinValue validation

MinValue validation

Old forum URL: forums.lhotka.net/forums/t/1287.aspx


ajj3085 posted on Wednesday, September 20, 2006

I must be missing something simple..

I want to use the CommonRule.MinValue, but I can't figure out how to set it up with ValidationRules.AddRule.

Just want to ensure a decimal value isn't less than 0.

JoeFallon1 replied on Wednesday, September 20, 2006

ValidationRules.AddRule(AddressOf MinValue(Of Integer), New MinValueRuleArgs(Of Integer)("myProperty", 0))

ajj3085 replied on Thursday, September 21, 2006

Hmm... VB isn't my thing.. I think in C# that would be..

ValidationRules.AddRule( CommonRules.MinValue<int>, new MinValueRuleArgs<int>( "myProperty", 0 ) );


Well, changing int to decimal of course.  Smile [:)]

I'll give that a shot, thanks!

brembot replied on Friday, September 22, 2006

How its gonna work with Short datatype with the default value is -1? I tried the validation rules it does not work if the value is -1 (negative 1) but if the value is 0 (zero) it works.

ValidationRules.AddRule(AddressOf CommonRules.MinValue(Of Short), New CommonRules.MinValueRuleArgs(Of Short)("MyProperty", 1))

ajj3085 replied on Friday, September 22, 2006

Are you making sure the rule is run after setting the default to -1?

brembot replied on Friday, September 22, 2006

Yes, I am sure. I have a variable which datatype is Short with default value is -1. When i execute the AddNew mehod of the bindingsource in debug mode, the validation rule is executed. i have some properties that have validation rules like integer, byte and string and it works very fine. i wonder, why my short datatype isn't working at all. It is binded to a textbox control having OnPropertyChanged events enabled. When i changed the value of the textbox to 0, the error provider works co'z i have implemented the rules of MinValue of 1 but when i set it to -1, it doesn't seem to work at all. Just only the short datatype has the problem to me.

Thanks

ajj3085 replied on Friday, September 22, 2006

Does VB Short translate to Int16 or UInt16?

brembot replied on Friday, September 22, 2006

By the way, Short translate to Int16.

Thanks

ajj3085 replied on Friday, September 22, 2006

The only thing I can suggest is set a break point on your rule and check the call stack to make sure its being called when the object is created.

brembot replied on Friday, September 22, 2006

Hello, I have here the attached sample project so that you can test it yourself. I think it is bug in ValidationRules or i am missing something.

Thanks in advance,

Marlon

RockfordLhotka replied on Friday, September 22, 2006

I haven't been following this thread, so this may not be useful. However, a few weeks ago someone reported a bug where my CompareTo code was checking for a result of -1 (which should be correct btw - CompareTo is supposed to return -1, 0 or 1) - but it turns out that didn't work with the Short (Int16) data type.

It appears that Int16's CompareTo implementation itself has a bug, where it returns an arbitrary negative number rather than just -1 like it is supposed to...

I implemented this fix/workaround for this in the version 2.1 code.

brembot replied on Saturday, September 23, 2006

RockfordLhotka:
I haven't been following this thread, so this may not be useful. However, a few weeks ago someone reported a bug where my CompareTo code was checking for a result of -1 (which should be correct btw - CompareTo is supposed to return -1, 0 or 1) - but it turns out that didn't work with the Short (Int16) data type.

It appears that Int16's CompareTo implementation itself has a bug, where it returns an arbitrary negative number rather than just -1 like it is supposed to...

I implemented this fix/workaround for this in the version 2.1 code.


Thanks Rocky for your information. Now, the short datatype will stop bugging me anymore.
Btw, Can you post the workaround for the Short Datatype.

ajj3085 replied on Friday, September 22, 2006

You're not calling ValidationRules.CheckRules anywhere except in the DataPortal_Create method.

Copyright (c) Marimer LLC