Do you spend most of your time writing custom validations on Windows Forms? Have you ever wanted an equivalent WinForm validator like in WebForm? Noogen
ValidationProvider can help you speed up your WinForms design time by providing powerful, easy and virtually code-free wiring of input validations.
For the beginners, I would suggest a reading of Paul Riley's article on Validators in ASP.NET/WebForms - ASP.NET Validators Unclouded. This is because
ValidationProvider engine is derived from WebForm Validators base.
ValidationProvider is also built on
ErrorProvider, see the article by Naveen K. Kohli - How To Use The ErrorProvider Object To Indicate Invalid Control State.
I know that this topic has been discussed many times (example MSDN article - Extending Windows Forms with a Custom Validation Component Library, Part 3), but most of the articles I've seen are either too restricted to a single control (
TextBox) or too complicated. My goal with Noogen
ValidationProvider is to bring all these great ideas together and simplify them.
- To speed up development, Noogen
ValidationProvider re-uses WebForm validator base engine and displays error using
ErrorProvider Control (hence the name
- My second goal is to provide easy wiring of basic/familiar validations as seen in WebForm, which includes: DataTypes check, required field, range and value comparison validations, and more...
ValidationProvider also tests and validates regular expressions and can even wire more advance custom validations.
I'll stop here before I go too far off from the topic. Of course, if you wish to drill down on the details, all the source codes are provided.
Using the code
ValidationProvider makes it easy to setup validation for
ComboBox controls. You don't have to write a single line of code. Just compile the accompanied source in release mode, browse and add it to your VS.NET IDE ToolBox, drop it on the form, and you are ready to visually design your input validations.
ValidationProvider property exposes Edit ValidationRules link/verb on the "Properties Window". I have also implemented
IExtenderProvider to enable easy editing of specific
ValidationRule ties to individual
The only code you will need is given below:
|Determine if the |
ValidationProvider supports a component.
|Get Error Icon alignment. |
|Get Error Icon padding. |
|Get validation rule. |
|Set Error Icon alignment. |
|Set Error Icon padding. |
|Set validation rule. |
|Overloaded. Perform validation on all controls. |
|Get validation error messages. |
Regular expression validations
ValidationProvider can test and validate regular expressions (
RegEx). For your convenience, a
RegEx test bench is provided.
RegEx test value applies the same validation engine, and the data gets validated as you type in. You can wire some very powerful and advance validations with
RegEx. With creativity, I believe that you can virtually use it in place of all the Basic Validations, but
RegEx can be complicated to derive. Thus, you would probably use
RegEx validation as an accommodation to the provided Basic Validations. The demo application demonstrates simple email and data length Regular Expression validations.
If you've worked with regular expressions before, then you would have probably collected some favorite
ValidationProvider allows you to load your collection
RegEx patterns so that you can re-use it consistently and share it with your developer friends. You would simply edit and add your
RegEx collection to the accompanied file "RegExPatternStore.xml" as seen in the animation above.
OK, I lied! The above code is not the only code you will need. When business logic gets complicated or if it is required to validate controls that the
ValidationProvider does not support, custom validation methods can be wired onto
ValidationProvider like this:
Noogen.Validation.ValidationRule vr = new Noogen.Validation.ValidationRule();
private void vr_CustomValidationMethod(object sender,
e.Value.ToString().Equals("abc") || e.Value.ToString().Equals("123") ;
e.ErrorMessage = "%ControlName% is not in ('abc', '123').";
Point of interest
For the purpose of demonstration, I have put both the
ValidationProvider in a single project. You would probably want to name your build of
ValidationProvider to separate the Designer from the Provider. This will reduce the assembly size, since the Designer is not required for deployment.
- April 11th, 2005 -
ValidationProvider 1.0 posted.