Version

ValidationTrigger Property (ValidationSettings)

Gets/sets a value which determines how validation is triggered.
Syntax
'Declaration
 
Public Property ValidationTrigger As ValidationTrigger
public ValidationTrigger ValidationTrigger {get; set;}
Remarks

When the ValidationTrigger is set to 'OnValidating' validation is initiated by the control's Validating event (or BeforeExitEditMode if the entity being validated is an embeddable editor). When set to 'OnPropertyValueChanged', it is initiated by the control's property changed event corresponding to the ValidationPropertyName (or ValueChanged if the entity being validated is an embeddable editor). When set to 'Programmatic', user interaction does not initiate a validation session; validation in that case only occurs when the Validate method is called.

Example
The following code sample demonstrates how a ValidationGroup can be used to programmatically validate more than one control, and how to customize the resulting notification:

Imports Infragistics.Win
Imports Infragistics.Win.Misc
Imports System.Drawing
Imports System.Drawing.Drawing2D

    Private Sub MakeValueRequired(ByVal ultraValidator As UltraValidator, ByVal textFields As List(Of TextBox))

        '  Clear the ValidationGroups collection of any existing members,
        '  and add one that will be assigned to the ValidationSettings for
        '  the specified controls.
        ultraValidator.ValidationGroups.Clear()
        Dim requiredFieldsGroup As ValidationGroup = ultraValidator.ValidationGroups.Add("Required")

        '  Create the ValidationSettings for each control
        Dim count As Integer = IIf(Not textFields Is Nothing, textFields.Count, 0)
        Dim i As Integer

        For i = 0 To count - 1

            Dim textBox As TextBox = textFields(i)
            Dim validationSettings As ValidationSettings = ultraValidator.GetValidationSettings(textBox)
            ValidationSettings.Reset()

            '  Assign the same group to each one
            ValidationSettings.ValidationGroup = requiredFieldsGroup

            '  Do not trigger validation on user interaction, only when the
            '  Validate method is called.
            ValidationSettings.ValidationTrigger = ValidationTrigger.Programmatic

            '  Use the value of the 'Text' property to provide the validation value
            ValidationSettings.ValidationPropertyName = "Text"

            '  Set IsRequired to true
            ValidationSettings.IsRequired = True
        Next

        '  Handle the UltraValidator's ValidationError event
        AddHandler ultraValidator.ValidationError, AddressOf Me.OnRequiredFieldValidationError
    End Sub

    Private Sub ValidateRequired(ByVal requiredFieldsGroup As ValidationGroup)

        '  Get a reference to the UltraValidator component.
        Dim ultraValidator As UltraValidator = requiredFieldsGroup.UltraValidator

        '  Call the Validate method to programmatically validate all controls
        '  that belong to the 'required fields' group. Allow the error images
        '  to be shown, but not the MessageBox.
        ultraValidator.Validate(requiredFieldsGroup, True, False)
    End Sub

    '  Handles the UltraValidator's ValidationError event for required field validations.
    Private Sub OnRequiredFieldValidationError(ByVal sender As Object, ByVal e As ValidationErrorEventArgs)

        Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
        sb.Append("The following required fields are currently empty:")
        sb.Append(Environment.NewLine)
        sb.Append(Environment.NewLine)

        Dim errors As ValidationResultsCollection = e.Validation.Errors
        Dim i As Integer

        For i = 0 To errors.Count - 1

            Dim result As ValidationResult = errors(i)
            sb.Append(String.Format("{0}{1}", result.ValidationSettings.Control.Name, Environment.NewLine))
        Next

        Dim ultraValidator As UltraValidator = sender
        MessageBox.Show(sb.ToString(), "Validation Error", MessageBoxButtons.OK, ultraValidator.MessageBoxIcon)
    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 MakeValueRequired( UltraValidator ultraValidator, List<TextBox> textFields )
    {
        //  Clear the ValidationGroups collection of any existing members,
        //  and add one that will be assigned to the ValidationSettings for
        //  the specified controls.
        ultraValidator.ValidationGroups.Clear();
        ValidationGroup requiredFieldsGroup = ultraValidator.ValidationGroups.Add( "Required" );

        //  Create the ValidationSettings for each control
        int count = textFields != null ? textFields.Count : 0;
        for ( int i = 0; i < count; i ++ )
        {
            TextBox textBox = textFields[i];
            ValidationSettings validationSettings = ultraValidator.GetValidationSettings( textBox );
            validationSettings.Reset();

            //  Assign the same group to each one
            validationSettings.ValidationGroup = requiredFieldsGroup;

            //  Do not trigger validation on user interaction, only when the
            //  Validate method is called.
            validationSettings.ValidationTrigger = ValidationTrigger.Programmatic;

            //  Use the value of the 'Text' property to provide the validation value
            validationSettings.ValidationPropertyName = "Text";

            //  Set IsRequired to true
            validationSettings.IsRequired = true;
        }

        //  Handle the UltraValidator's ValidationError event
        ultraValidator.ValidationError += new ValidationErrorHandler( this.OnRequiredFieldValidationError );
    }

    private void ValidateRequired( ValidationGroup requiredFieldsGroup )
    {
        //  Get a reference to the UltraValidator component.
        UltraValidator ultraValidator = requiredFieldsGroup.UltraValidator;

        //  Call the Validate method to programmatically validate all controls
        //  that belong to the 'required fields' group. Allow the error images
        //  to be shown, but not the MessageBox.
        ultraValidator.Validate( requiredFieldsGroup, true, false );
    }

    //  Handles the UltraValidator's ValidationError event for required field validations.
    private void OnRequiredFieldValidationError( object sender, ValidationErrorEventArgs e )
    {
        StringBuilder sb = new StringBuilder();
        sb.Append( "The following required fields are currently empty:" );
        sb.Append( Environment.NewLine );
        sb.Append( Environment.NewLine );

        ValidationResultsCollection errors = e.Validation.Errors;
        for ( int i = 0; i < errors.Count; i ++ )
        {
            ValidationResult result = errors[i];
            sb.Append ( string.Format("{0}{1}", result.ValidationSettings.Control.Name, Environment.NewLine) );
        }

        UltraValidator ultraValidator = sender as UltraValidator;
        MessageBox.Show( sb.ToString(), "Validation Error", MessageBoxButtons.OK, ultraValidator.MessageBoxIcon );
    }
Requirements

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

See Also