Validates all controls associated with this instance.
'Declaration
Public Overloads Function Validate( _
ByVal As Boolean _
) As Validation
Parameters
- showErrorImage
- Specifies whether to show the Image for each control that fails validation.
Return Value
A
Validation instance which describes the result of the validation.
The following code sample demonstrates how to use the Validating event to receive a notification when each control is validated:
Imports Infragistics.Win
Imports Infragistics.Win.Misc
Imports System.Drawing
Imports System.Drawing.Drawing2D
Dim validations As New List(Of ValidatingEventArgs)
Private Overloads Sub Validate(ByVal ultraValidator As UltraValidator, ByVal control As Control, ByVal showErrorImage As Boolean, ByVal showMessageBox As Boolean)
' Handle the Validating event.
AddHandler ultraValidator.Validating, AddressOf Me.OnValidatorValidating
Me.validations.Clear()
If control Is Nothing Then
ultraValidator.Validate(showErrorImage, showMessageBox)
Else
ultraValidator.Validate(control)
End If
Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
Dim i As Integer
For i = 0 To validations.Count - 1
Dim args As ValidatingEventArgs = validations(i)
Dim message As String = String.Empty
Dim passedOrFailed = IIf(args.IsValid, "passed", "failed")
message = String.Format("Validation for '{0}' {1}. Value = '{2}', Status = {3}", args.Control.Name, passedOrFailed, args.Value, args.Status)
sb.Append(message)
sb.Append(Environment.NewLine)
Next
MessageBox.Show(sb.ToString())
End Sub
Private Sub OnValidatorValidating(ByVal sender As Object, ByVal e As ValidatingEventArgs)
Me.validations.Add(e)
End Sub
'Declaration
Public Overloads Function Validate( _
ByVal As Boolean _
) As Validation
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Infragistics.Win;
using Infragistics.Win.Misc;
using System.Drawing;
using System.Drawing.Drawing2D;
private void Validate( UltraValidator ultraValidator, Control control, bool showErrorImage, bool showMessageBox )
{
List<ValidatingEventArgs> validations = new List<ValidatingEventArgs>();
// Use an anonymous method to handle the Validating event.
ValidatingHandler handler =
delegate(object sender, ValidatingEventArgs e )
{
// Add each instance to record the event firings
validations.Add( e );
};
ultraValidator1.Validating += handler;
if ( control == null )
ultraValidator.Validate( showErrorImage, showMessageBox );
else
ultraValidator.Validate( control );
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for ( int i = 0; i < validations.Count; i ++ )
{
ValidatingEventArgs args = validations[i];
string message = string.Empty;
string passedOrFailed = args.IsValid ? "passed" : "failed";
message = string.Format( "Validation for '{0}' {1}. Value = '{2}', Status = {3}", args.Control.Name, passedOrFailed, args.Value, args.Status );
sb.Append( message );
sb.Append( Environment.NewLine );
}
MessageBox.Show( sb.ToString() );
}
'Declaration
Public Overloads Function Validate( _
ByVal As Boolean _
) As Validation
Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2