Hi,
I have a MDIParent form and 2 child forms. One of them,form1, has a textbox for which certain validations are present in the validating event. The other one has a button on it. When I try to navigate from form1 to form2, the validating event is firing twice for the first time. Is there a way to make it fire only once. And also, this event fires whenever I try to close the mdi parent form
Attached is a sample project.
Thank you.
Your biggest problem here is that your Form1 only has the Textbox on it, so obviously that will make validation very difficult. What I'd do, if I were you, is to add a button to Form1, so that the focus can leave the Texbox. I'll add this in the Leave event of the TextBox :
Code:
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
If blnShown = False Then
If (TextBox1.Text <> "text") Then
MessageBox.Show("wrong text")
blnShown = True
End If
End If
End Sub
And add this boolean variable. This will help ensuring that the MsgBox gets displayed only once.
I am attaching my example here for you.
Also, please try to add code next time when you make a thread; people tend not to download things if they don't have any idea of what to look for.
Is it possible that the button_click event of the second form never fires(though the button is clicked) until the validation for the form1 text box succeeds.
I will give a background of the problem. I have migrated some vb6 code in the lost focus event of the textbox, wherein the control is always set back to the textbox whenever the validation fails, after displaying a message box.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.