DateTimePicker-ValueChanged问题 [英] DateTimePicker - Problem with ValueChanged

查看:199
本文介绍了DateTimePicker-ValueChanged问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我使用两个DateTimePickers来限制数据查询的结果

我也不希望用户能够将StartDate设置为EndDate之后.

问题是,如果我使用Value更改,而您又更改为另一个月,则将触发ValueChange事件,这将导致我的查询运行.

更糟糕的是,我正在验证Value change事件的开始日期和结束日期,因此在下面的代码中,如果DateTo值是3月3日,From是2月20日,而您将DateFrom的月份更改为March DateFrom的值更改为3月20日,并且甚至在您要在DateFrom框中选择的实际日期上单击之前,查询就会运行TWICE.

是否只有在单击月份的实际日期时才捕获事件,而在选择月份时忽略更改的方法?

我尝试使用LostFocus事件,但是在事件触发之前,您必须单击另一个控件-不酷.



Hi
I use two DateTimePickers to restrict the results of a data query

I also dont want users to be able to set the StartDate to be After the EndDate.

The problem is that if I use the Value changed, and you change to another month, the ValueChange Event is fired, and this causes my query to run.

Even worse, I am validating the start and end dates on the Value changed event, so in the code below, if the DateTo value was on 3 March, and the From was on 20 Feb, and you change the month of DateFrom to March the value of the DateFrom changes to 20 Mar, and the Query is run TWICE before you have even clicked on the actual day you want to select in The DateFrom box.

Is there a way to only catch the event when an actual day of the month is clicked, and ignore the change while you are selecting the month?

I tried using LostFocus event, but then you have to click another control before the event is fired - not cool.



Private Sub dtpStkHistDateFrom_ValueChanged(sender As System.Object, e As System.EventArgs) Handles dtpStkHistDateFrom.ValueChanged
       If Me.dtpStkHistDateFrom.Value > Me.dtpStkHistDateTo.Value Then Me.dtpStkHistDateTo.Value = Me.dtpStkHistDateFrom.Value
       GetStkHist()
   End Sub

   Private Sub dtpStkHistDateTo_ValueChanged(sender As System.Object, e As System.EventArgs) Handles dtpStkHistDateTo.ValueChanged
       If Me.dtpStkHistDateTo.Value < Me.dtpStkHistDateFrom.Value Then Me.dtpStkHistDateFrom.Value = Me.dtpStkHistDateTo.Value
       GetStkHist()
   End Sub

推荐答案

尝试使用

这篇关于DateTimePicker-ValueChanged问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆