Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not trigger datepicker.valuechanged event when browsing month in date picker

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!

like image 485
Summer Avatar asked Feb 22 '23 23:02

Summer


1 Answers

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
like image 101
LarsTech Avatar answered Apr 06 '23 15:04

LarsTech