By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,069 Members | 1,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,069 IT Pros & Developers. It's quick & easy.

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

P: n/a

' 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 .
Oct 14 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.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...

Oct 14 '08 #2

P: n/a
What is the connection between the textbox1 and datetimepicker? Is the
datetimepicker setting the text in the textbox when you change the date?

<ft*****@gmail.comwrote in message
news:bf**********************************@l33g2000 pri.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 .
Oct 14 '08 #3

P: n/a
On Oct 14, 3:04*pm, karim <ka...@discussions.microsoft.comwrote:
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
Oct 15 '08 #4

P: n/a
On Oct 15, 2:16*am, "Family Tree Mike"
<FamilyTreeM...@ThisOldHouse.comwrote:
What is the connection between the textbox1 and datetimepicker? *Is the
datetimepickersettingthe text in thetextbox when youchangethe date?

<fts2...@gmail.comwrote in message

news:bf**********************************@l33g2000 pri.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. )
Oct 15 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.