I am using vb.net. I add a date picker as follows
Friend WithEvents dtpReportDate As System.Windows.Forms.DateTimePicker
The default date picker has left arrow and right arrow which allow you to browser previous month and following month. I add a handler to date picker valuechanged event:
AddHandler dtpReportDate.ValueChanged, AddressOf dtpReportDateChanged
Private Sub dtpReportDateChanged(ByVal sender As Object, ByVal e As System.EventArgs)
'do something here
End Sub
The problem is that whenever I click left arrow or right arrow to change month, the dptReportDateChanged is triggered. I do not want this happens. All I want is that after I find a month, I double click date to trigger the event.
Thanks a lot!
Try this:
Private Sub DateTimePicker1_ValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DateTimePicker1.ValueChanged
Me.Text = DateTimePicker1.Value.ToString
End Sub
Private Sub DateTimePicker1_DropDown(ByVal sender As Object, ByVal e As EventArgs) Handles DateTimePicker1.DropDown
RemoveHandler DateTimePicker1.ValueChanged, AddressOf DateTimePicker1_ValueChanged
End Sub
Private Sub DateTimePicker1_CloseUp(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.CloseUp
AddHandler DateTimePicker1.ValueChanged, AddressOf DateTimePicker1_ValueChanged
Call DateTimePicker1_ValueChanged(sender, EventArgs.Empty)
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With