TypeValidationEventArgs.IsValidInput Property


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

 property bool IsValidInput { bool get(); };
public bool IsValidInput { get; }
member this.IsValidInput : bool
Public ReadOnly Property IsValidInput As Boolean

Property Value

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


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" );
Private Sub MaskedTextBox1_TypeValidationCompleted(sender as Object, e as TypeValidationEventArgs) _ 
     Handles MaskedTextBox1.TypeValidationCompleted

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "Cancel", e.Cancel)
    messageBoxVB.AppendFormat("{0} = {1}", "IsValidInput", e.IsValidInput)
    messageBoxVB.AppendFormat("{0} = {1}", "Message", e.Message)
    messageBoxVB.AppendFormat("{0} = {1}", "ReturnValue", e.ReturnValue)
    messageBoxVB.AppendFormat("{0} = {1}", "ValidatingType", e.ValidatingType)
    MessageBox.Show(messageBoxVB.ToString(),"TypeValidationCompleted Event")

End Sub


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.

Applies to

See also