Main Page | Report this Page
 
   
.NET DotNet Forum Index  »  VB.NET Forum (Visual Basic .NET)  »  Why does TextBox's validating not work when using...
Page 1 of 1    
Author Message
fts2012 at (no spam) gmail.com...
Posted: Mon Oct 13, 2008 3:08 pm
Guest
' if the textbox is empty show an error message 1001
Private Sub TextBox1_Validating(ByVal sender As System.Object,
ByVal e As System.ComponentModel.CancelEventArgs) Handles
TextBox1.Validating
TextBox1.BackColor = Color.White
If TextBox1.Text.Length = 0 Then
TextBox1.Select()
TextBox1.BackColor = 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 .
fts2012 at (no spam) gmail.com...
Posted: Tue Oct 14, 2008 7:21 pm
Guest
On Oct 14, 3:04 pm, karim <ka... at (no spam) discussions.microsoft.com> wrote:
Quote:
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.Validating>         TextBox1.BackColor = Color.White
        If TextBox1.Text.Length = 0 Then
            TextBox1.Select()
            else
            TextBox1.BackColor = Color.Yellow
            MsgBox("1001")
            e.Cancel = True
        End If

Hope this helps...

Thanks.
This problem was solved.
It was caused by the "TextBox1.select()".
code as bellow will be right.
Private Sub TextBox1_Validating(ByVal sender As System.Object,
ByVal e As System.ComponentModel.CancelEventArgs) Handles
TextBox1.Validating
TextBox1.BackColor = Color.White
If TextBox1.Text.Length = 0 Then
' TextBox1.Select()
TextBox1.BackColor = Color.Yellow
MsgBox("1001")
e.Cancel = True
End If
End Sub
fts2012 at (no spam) gmail.com...
Posted: Tue Oct 14, 2008 7:27 pm
Guest
On Oct 15, 2:16 am, "Family Tree Mike"
<FamilyTreeM... at (no spam) ThisOldHouse.com> wrote:
Quote:
What is the connection between the textbox1 and datetimepicker?  Is the
datetimepickersettingthe text in thetextbox when youchangethe date?

fts2... at (no spam) gmail.com> wrote in message

news:bfc3ac1e-e62c-460a-b2ef-3bf38a8d6c2f at (no spam) l33g2000pri.googlegroups.com...



   ' if the textbox is empty show an error message 1001
   Private Sub TextBox1_Validating(ByVal sender As System.Object,
ByVal e As System.ComponentModel.CancelEventArgs) Handles
TextBox1.Validating
       TextBox1.BackColor = Color.White
       If TextBox1.Text.Length = 0 Then
           TextBox1.Select()
           TextBox1.BackColor = 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. )
 
Page 1 of 1       All times are GMT - 5 Hours
The time now is Thu Jan 08, 2009 6:38 am