Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.



VB
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
Posted
Updated 25-Feb-12 20:09pm
v2

1 solution

Try the CloseUp Event[^].
 
Share this answer
 
Comments
Richard.Berry100 26-Feb-12 2:59am    
Perfect - Thanks!!!
Sander Rossel 26-Feb-12 3:37am    
No problem :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900