The IsValid property is settable, and as such, any listener in the notification chain can set the property to a value that does not reflect the actual result of the validation. If the IsValid property was false at the time the Validating event was fired, but true when execution returns, the ValidationError event is not fired; conversely, if the value was set from true to false by an event listener, the ValidationError event will be fired, and any subsequent notification actions will take place.
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
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() ); }
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