Hot File

Validators for Windows Forms - ValidationProvider Control

View: 5291    Dowload: 2   Comment: 0   Post by: naruto  
Author: none   Category: Design Ideas   Fields: Accounting

0 point/8 review File has been tested

Download   validators-for-windows-forms.rar (134.40 KB)

You need to Sign In to download the file validators-for-windows-forms.rar
If you do not have an account then Sign up for free here

Download error   Report copyright violation

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.

Introduction

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.

Noogen 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.

The design

  1. To speed up development, Noogen ValidationProvider re-uses WebForm validator base engine and displays error using ErrorProvider Control (hence the name ValidationProvider).
  2. 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...
  3. Noogen 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

Basic Validations

ValidationProvider makes it easy to setup validation for TextBox and 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 TextBox or ComboBox controls.

The only code you will need is given below:

//
// Call Noogen ValidationProvider public method - 
// Validate() and display error if returns false.
//
this.validationProvider1.ValidationMessages(
                      !this.validationProvider1.Validate());

Public Methods

CanExtend Determine if the ValidationProvider supports a component.
GetIconAlignment Get Error Icon alignment.
GetIconPadding Get Error Icon padding.
GetValidationRule Get validation rule.
SetIconAlignment Set Error Icon alignment.
SetIconPadding Set Error Icon padding.
SetValidationRule Set validation rule.
Validate Overloaded. Perform validation on all controls.
ValidationMessages 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 RegEx patterns. 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.

Custom Validations

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:

//
// Create new ValidationRule and wire-up custom validation method.  
// This can be somewhere in the ctor.
//
Noogen.Validation.ValidationRule vr = new Noogen.Validation.ValidationRule();
vr.CustomValidationMethod += 
 new Noogen.Validation.CustomValidationEventHandler(vr_CustomValidationMethod);
this.validationProvider1.SetValidationRule(this.textBox6, vr);
//
// The custom validation method.
//
private void vr_CustomValidationMethod(object sender, 
                 Noogen.Validation.CustomValidationEventArgs e)
{
   e.IsValid = 
        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 Noogen.Validation.Design and 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.

Validators for Windows Forms - ValidationProvider Control

Validators for Windows Forms - ValidationProvider Control Posted on 22-04-2014  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. 5/10 5291

Comment:

To comment you must be logged in members.

Files with category

  • MasterPages reinvented - a Component Based Template Engine for ASP.NET

    View: 1618    Download: 2   Comment: 0   Author: none  

    MasterPages reinvented - a Component Based Template Engine for ASP.NET

    Category: Design Ideas
    Fields: Other

    2.25/2 review
    A template engine allows you to render the contents of your ASP.NET web forms as parts of a Master Page (template). This template engine provides a new approach regarding the separation of ASP.NET templates and web forms. The features at a...

  • A Quick Look at API Design

    View: 1224    Download: 0   Comment: 0   Author: none  

    A Quick Look at API Design

    Category: Design Ideas
    Fields: Other

    0/0 review
    Whether you know it or not, you are an API (Application Programmer Interface) designer. Every time you create a new class or enhance an existing one, the non-private methods and properties create, or add to, an API. So it makes sense, I think, to...

  • User-driven applications

    View: 2168    Download: 0   Comment: 0   Author: none  

    User-driven applications

    Category: Design Ideas
    Fields: Other

    0/4 review
    This is the second article in a series of two. The first article – on the theory of moveable objects – was about the basic algorithm and its use in designing different moveable / resizable objects. Such objects are in high demand in many programming...

  • A Reflective and Translucent Glass Panel

    View: 2710    Download: 3   Comment: 0   Author: none  

    A Reflective and Translucent Glass Panel

    Category: Design Ideas
    Fields: Other

    0/7 review
    This component is the logical suite of the AlphaGradientPanel published here on CodeProject. It replaces the original System.Windows.Form.Panel by a nifty glassy one.

  • Distributed Command Pattern - an extension of command pattern for connected systems

    View: 3586    Download: 4   Comment: 0   Author: none  

    Distributed Command Pattern - an extension of command pattern for connected systems

    Category: Design Ideas
    Fields: Accounting

    0/7 review
    Distributed Command Pattern is a proposed pattern for solving the extra architectural design issues which need to be considered for connected systems than designing regular applications. The goal of this pattern is to “Have the same design for both...

  • Validators for Windows Forms - ValidationProvider Control

    View: 5291    Download: 2   Comment: 0   Author: none  

    Validators for Windows Forms - ValidationProvider Control

    Category: Design Ideas
    Fields: Accounting

    0/8 review
    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...

  • Integrating Help In Your Iron Speed Designer Application

    View: 1599    Download: 0   Comment: 0   Author: none  

    Integrating Help In Your Iron Speed Designer Application

    Category: Design Ideas
    Fields: Computers - Technology

    0/2 review
    This article is in the Product Showcase section for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.

  • Dependency Inversion Principle and the Dependency Injection Pattern

    View: 836    Download: 0   Comment: 0   Author: none  

    Dependency Inversion Principle and the Dependency Injection Pattern

    Category: Design Ideas
    Fields: Computers - Technology

    0/2 review
    Everyday we write lots of code which are tightly coupled and when complexity grows code will eventually deteriorate into Spaghetti Code. Which violates the Dependency inversion principle. In software design, tight coupling is often considered to be a...

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd