Use Multiple Error Providers with a Validator

Navigation:  How To... >

Use Multiple Error Providers with a Validator

Previous pageReturn to chapter overviewNext page

The most natural solution is to use an Error Providers Group as the Error Provider for the Validator of this control.

 

Let's consider the same example as in How to Use Multiple Validators for a Control walk-through, but so that possible errors are to be indicated in the following ways:

 

1.if NGEdit1 is empty, a message box should be displayed;

2.if NGEdit1 doesn't contain a valid email address, a message should be displayed by a NGSimpleLabel1 label component;

3.if the value in NGEdit1 doesn't match the value in NGEdit2, a hint for this control should be displayed.

 

It can be achieved by use of Error Providers Group component which references three Validator components:

 

1.TNGMessageBoxErrorProvider;

2.TNGControlErrorProvider;

3.TNGHintErrorProvider;

 

The following steps have to be performed:

 

1.Place TNGMessageBoxErrorProvider component (NGMessageBoxErrorProvider1) on a form; set its MaxErrorLevel and MinErrorLevel properties to 3.

2.Place TNGControlErrorProvider component (NGControlErrorProvider1) on a form; set its MaxErrorLevel and MinErrorLevel properties to 2, its Control property to LMDSimpleLabel1;

3.Place TNGHintErrorProvider component (NGHintErrorProvider1) on a form; set its MaxErrorLevel and MinErrorLevel properties to 1;

4.Place TNGErrorProvidersGroup component (NGErrorProvidersGroup1) on a form

4.1. Add an item to its Providers collection, set its Provider property to NGMessageBoxErrorProvider1;

4.2. Add an item to its Providers collection, set its Provider property to NGControlErrorProvider1;

4.3. Add an item to its Providers collection, set its Provider property to NGHintErrorProvider1;

5.Perform steps 2-5.3 from How to use multiple validators for a control walk-through;

6.Add an item to the Providers collection of NGValidationGroup1, set its Provider property to NGErrorProvidersGroup1.

 

Now the errors in field NGEdit1 should be indicated as formulated above.

 

Note: In this example Error Provider components could be added directly to the Providers collection of NGValidationGroup1. However, if not a Validation Group but a single Validator is used for a control, use of Error Providers Group is the best option.