0

Hi Everyone,

In my form there is a "Validating" event on a textbox.

This form also has a "Cancel" button.

Is there a way to not execute the "Validating" event when the user clicks on the "Cancel" button?

Please show me code to do this.

Thanks.

Truly,
Emad

2
Contributors
2
Replies
9
Views
6 Years
Discussion Span
Last Post by emaduddeen
1

See if this helps for bypassing the Validation of a TextBox.
1 TextBox, 1 Button

Public Class Form1
    Private bValidateTextBox As Boolean = True

    Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
        bValidateTextBox = False '// Disable Validation.
    End Sub

    Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
        bValidateTextBox = True '// Enable Validation.
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '// do stuff here.
        MsgBox("TextBox Validation was Canceled") '// for testing.
    End Sub

    Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
        If bValidateTextBox Then
            '// validating code here.
            MsgBox(TextBox1.Text) '// for testing.
        End If
    End Sub
End Class

Edited by codeorder: typo

Votes + Comments
CodeOrder was very helpful.
0

Hi CodeOrder,

Thanks for your help. It works very well.

Truly,
Emad

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.