开发者

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

开发者 https://www.devze.com 2023-04-04 20:06 出处:网络
I am using vb.net. I add a date picker as follows Friend WithEvents dtpReportDate As System.Windows.Forms.DateTimePicker

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)

开发者_C百科

'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


Or you can just trigger off the CloseUp event instead of ValueChanged. That worked well enough for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消