CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2010
    Posts
    18

    textbox validating firing twice

    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.
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Smile Re: textbox validating firing twice

    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.

    Hannes
    Attached Files Attached Files

  3. #3
    Join Date
    Jun 2010
    Posts
    18

    Re: textbox validating firing twice

    Thanks for a quick reply. Will do it next time.

    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.

    Thank you....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured