Why does TextBox's validating not work when using DateTimePicker?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fts2012@gmail.com

    #1

    Why does TextBox's validating not work when using DateTimePicker?


    ' if the textbox is empty show an error message 1001
    Private Sub TextBox1_Valida ting(ByVal sender As System.Object,
    ByVal e As System.Componen tModel.CancelEv entArgs) Handles
    TextBox1.Valida ting
    TextBox1.BackCo lor = Color.White
    If TextBox1.Text.L ength = 0 Then
    TextBox1.Select ()
    TextBox1.BackCo lor = Color.Yellow
    MsgBox("1001")
    e.Cancel = True
    End If
    End Sub

    but if I click the DateTimePicker, the message "1001" will be
    displayed twice, and then as long as I click the left mouse , it will
    be showed twice.
    Can anybody tell me how to deal with it ?
    Thanks .
  • =?Utf-8?B?a2FyaW0=?=

    #2
    RE: Why does TextBox's validating not work when using DateTimePicker?

    Hello, from what I see in you code, I think you need to use (Else) if you
    don't want the msg (1001) to come up. but the way you have it now the msg
    will come up every time you click your txt box. see if this will work...
    TextBox1.Valida ting
    TextBox1.BackCo lor = Color.White
    If TextBox1.Text.L ength = 0 Then
    TextBox1.Select ()
    else
    TextBox1.BackCo lor = Color.Yellow
    MsgBox("1001")
    e.Cancel = True
    End If
    Hope this helps...

    Comment

    • Family Tree Mike

      #3
      Re: Why does TextBox's validating not work when using DateTimePicker?

      What is the connection between the textbox1 and datetimepicker? Is the
      datetimepicker setting the text in the textbox when you change the date?

      <fts2012@gmail. comwrote in message
      news:bfc3ac1e-e62c-460a-b2ef-3bf38a8d6c2f@l3 3g2000pri.googl egroups.com...
      >
      ' if the textbox is empty show an error message 1001
      Private Sub TextBox1_Valida ting(ByVal sender As System.Object,
      ByVal e As System.Componen tModel.CancelEv entArgs) Handles
      TextBox1.Valida ting
      TextBox1.BackCo lor = Color.White
      If TextBox1.Text.L ength = 0 Then
      TextBox1.Select ()
      TextBox1.BackCo lor = Color.Yellow
      MsgBox("1001")
      e.Cancel = True
      End If
      End Sub
      >
      but if I click the DateTimePicker, the message "1001" will be
      displayed twice, and then as long as I click the left mouse , it will
      be showed twice.
      Can anybody tell me how to deal with it ?
      Thanks .

      Comment

      • fts2012@gmail.com

        #4
        Re: Why does TextBox's validating not work when using DateTimePicker?

        On Oct 14, 3:04 pm, karim <ka...@discussi ons.microsoft.c omwrote:
        Hello, from what I see in you code, I think you need to use (Else) if you
        don't want the msg (1001)to comeup. but the way you have it now themsg
        will come up every time you click your txt box. see if this will work...
        TextBox1.Valida ting        TextBox1.BackCo lor = Color.White
                If TextBox1.Text.L ength = 0 Then
                    TextBox1.Select ()
                    else
                    TextBox1.BackCo lor = Color.Yellow
                    MsgBox("1001")
                    e.Cancel = True
                End If
        >
        Hope this helps...
        Thanks.
        This problem was solved.
        It was caused by the "TextBox1.selec t()".
        code as bellow will be right.
        Private Sub TextBox1_Valida ting(ByVal sender As System.Object,
        ByVal e As System.Componen tModel.CancelEv entArgs) Handles
        TextBox1.Valida ting
        TextBox1.BackCo lor = Color.White
        If TextBox1.Text.L ength = 0 Then
        ' TextBox1.Select ()
        TextBox1.BackCo lor = Color.Yellow
        MsgBox("1001")
        e.Cancel = True
        End If
        End Sub

        Comment

        • fts2012@gmail.com

          #5
          Re: Why does TextBox's validating not work when using DateTimePicker?

          On Oct 15, 2:16 am, "Family Tree Mike"
          <FamilyTreeM... @ThisOldHouse.c omwrote:
          What is the connection between the textbox1 and datetimepicker?  Is the
          datetimepickers ettingthe text in thetextbox when youchangethe date?
          >
          <fts2...@gmail. comwrote in message
          >
          news:bfc3ac1e-e62c-460a-b2ef-3bf38a8d6c2f@l3 3g2000pri.googl egroups.com...
          >
          >
          >
             ' if the textbox is empty show an error message 1001
             Private Sub TextBox1_Valida ting(ByVal sender As System.Object,
          ByVal e As System.Componen tModel.CancelEv entArgs) Handles
          TextBox1.Valida ting
                 TextBox1.BackCo lor = Color.White
                 If TextBox1.Text.L ength = 0 Then
                     TextBox1.Select ()
                     TextBox1.BackCo lor = Color.Yellow
                     MsgBox("1001")
                     e.Cancel = True
                 End If
             End Sub
          >
          but if I click the DateTimePicker, the message "1001" will be
          displayed twice, and then as long as I click the left mouse , it will
          be showed twice.
          Can anybody tell me how to deal with it ?
          Thanks .
          the connection is the check, when the focus move to the
          datetimepicker, it should check the content of textbox.
          (thanks for your reply,the problem was solved. )

          Comment

          Working...