TypeValidationEventArgs.IsValidInput Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets a value indicating whether the formatted input string was successfully converted to the validating type.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public bool IsValidInput { get; }

Property Value

Type: System.Boolean

true if the formatted input string can be converted into the type specified by the ValidatingType property; otherwise, false.

The IsValidInput property indicates the success of the Parse method found in the Type represented by the ValidatingType property. This type must contain Parse method(s) having one or both of the following signatures:

public static Object Parse(string)

public static Object Parse(string, IFormatProvider)

Parse is called before the MaskedTextBox control raises the TypeValidationCompleted event. This method is invoked with the contents, minus the prompt characters, of the Text property of the MaskedTextBox class. If successful, it returns the converted object; otherwise, it returns null.

For more information about the type validation process, see the TypeValidationCompleted event.

The following code example demonstrates the use of this member. In the example, an event handler reports on the occurrence of the MaskedTextBox.TypeValidationCompleted event. This report helps you to learn when the event occurs and can assist you in debugging. To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

To run the example code, paste it into a project that contains an instance of type MaskedTextBox named MaskedTextBox1. Then ensure that the event handler is associated with the MaskedTextBox.TypeValidationCompleted event.

private void MaskedTextBox1_TypeValidationCompleted(Object sender, TypeValidationEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Cancel", e.Cancel );
messageBoxCS.AppendFormat("{0} = {1}", "IsValidInput", e.IsValidInput );
messageBoxCS.AppendFormat("{0} = {1}", "Message", e.Message );
messageBoxCS.AppendFormat("{0} = {1}", "ReturnValue", e.ReturnValue );
messageBoxCS.AppendFormat("{0} = {1}", "ValidatingType", e.ValidatingType );
MessageBox.Show(messageBoxCS.ToString(), "TypeValidationCompleted Event" );

.NET Framework
Available since 2.0
Return to top