DateTimePicker_ValueChanged issues

limbrian

Member
Joined
Sep 26, 2006
Messages
5
Programming Experience
Beginner
I am using VB.net 2005.
I have a problem when datetimepicker value changed.
I writen a function with message prompt when datetimepicker value changed.

PROBLEM
1. The message box is prompted out until non-stop.
2. Value changed event keep looping
3. Continues increasing the month value on the datetimepicker.


Izzit messagebox not compatible with datetimepicker value changed event?
 
1. Windows Forms questions go in the Windows Forms forum. Moved.
2. The ValueChanged event is raised whenever the Value property changes. If the month value changes then either the user is doing it or your code is doing it. If you know it's not the user then it must be the code. If we can't see the code we can't tell what's wrong with it.
 
VB.NET:
PrivateSub dtpSuspendTo_ValueChanged(ByVal sender AsObject, ByVal e As System.EventArgs) Handles dtpSuspendTo.ValueChanged
MessageBox.Show("The selected value is " & dtpSuspendTo.Value)
EndSub

This is the simple code that i using.
 
Last edited by a moderator:
This code works fine for me when just selecting another date. The problem was reproduced when clicking 'next month', where probably the messagebox causes a problem for the inner logic when DTP control changes month..?
 
Well that's freaky! I take back what I said about it being your code, but it is a good idea to give us all the information. If something is happening only under very specific circumstances, like when you click the buttons on the calendar to change month, then you really should say so. The original post sounded like it was happening every time you changed the date. I would guess that the loss of focus somehow causes the buttons to raise an additional event, which then gets into a cycle. You might want to do something like this to avoid dispaying the message when the calendar is displayed:
VB.NET:
Private droppedDown As Boolean = False

Private Sub dtpSuspendTo_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpSuspendTo.DropDown
    Me.droppedDown = True
End Sub

Private Sub dtpSuspendTo_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpSuspendTo.CloseUp
    Me.droppedDown = False
    MessageBox.Show("The selected value is " & dtpSuspendTo.Value)
End Sub

Private Sub dtpSuspendTo_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpSuspendTo.ValueChanged
    If Not Me.droppedDown Then
        MessageBox.Show("The selected value is " & dtpSuspendTo.Value)
    End If
End Sub
 
Back
Top