errorprovider and BindingSource, but no errors until user clicks Ok

errorprovider and BindingSource, but no errors until user clicks Ok

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


l.vanderdonk posted on Thursday, March 19, 2009

Hi There,

Does anybody know if there is an easier way of avoiding errors of errorprovider on CreateObject on a windowsform than the one Rocky suggested 07-16-2007 (see article), I want to keep the call to CheckRules() in create of the BO. Im posting this because it's some time ago and there might be an easier way of doing this(due to an update of csla ed).

http://forums.lhotka.net/forums/thread/16132.aspx

Thanks in advance.

Best Regards,

Laurens van der Donk

 

 

RockfordLhotka replied on Friday, March 20, 2009

Yes, I recently posted about this on another thread. You can use the short-circuiting feature of the business rules subsystem in CSLA to do this. The basic steps are:

  1. Define a property (it can be private) in your object that returns true/false based on whether you want rules to execute (you'll probably base this property on IsNew and other factors)
  2. Create a rule method that always returns true (success), but which manually short-circuits business rule processing based on the property from step 1
  3. Add this rule to all your properties at priority -1, so it runs before any other rules

This will suppress all rules from running until the property in step 1 says they should run.

Then in your Save() method override, you'll to change the property in step 1, call ValidationRules.CheckRules() to check all the rules, and throw a ValidationException if the object isn't valid to prevent the user from creating an object with invalid data.

l.vanderdonk replied on Saturday, March 21, 2009

Hi Rocky,

This will help. Thanks a lot for your reply.

Laurens

Copyright (c) Marimer LLC