Integrating with Windows Forms

Microsoft Enterprise Library 5.0

DropDown image DropDownHover image Collapse image Expand image CollapseAll image ExpandAll image Copy image CopyHover image

You can integrate the Validation Application Block with Windows Forms applications. For example, you can use the application block to validate information a user enters into a Windows Form. Windows Forms is integrated with the Validation Application Block through the types defined in the Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WinForms assembly.

The ValidationProvider class defined in this assembly provides the main integration point. This class is an extender provider that adds properties to Windows Forms controls. This provider allows you to specify how to use the Validation Application Block to validate the controls' values.

You can perform validation automatically by using the Control.Validating event or you can initiate it in your code by invoking the ValidationProvider.PerformValidation(Control) method. In both cases, you must use the validation provider to configure the control.

You can also specify an instance of the ErrorProvider class for the control. If you do this, the validation errors that result if the validation fails are sent to the error provider as a properly formatted error message.

The ValidationProvider.Enabled property enables and disables the validation provider. When it is disabled no validation occurs, the validation provider is considered valid, and any error messages posted to the ErrorProvider are cleared. When it is re-enabled, the provider continues to be valid and does not post any error messages until validation is triggered again.