Note that there are some explanatory texts on larger screens.

plurals
  1. PODateTimePicker: Selecting a range of hours within a single day only
    text
    copied!<p>I'm looking for a way to use two DateTimePicker controls to select a range of hours and minutes within one day. That is, to basically select a 'starting time' and 'ending time'.</p> <p>I started with two DateTimePicker controls with the custom format of h:mm tt. I tried adding (on ValueChanged), a check that made the selected 'starting time' will become the 'ending times' minimum and vice versa, the 'ending time' becoming the 'starting times' maximum (sorry its hard to explain, but thanks for your patience!)</p> <p>However, that approach didn't seem to work -- I was still able to select 11.00 AM on the 'ending time' and 1.00 PM on the 'starting time'. I have a feeling that the current day of the timestamp has something to do with it (e.g. the starting time is of the previous day, and therefore is less).</p> <p>I thought about changing to a combo box of preset half hour intervals throughout the day; however the minutes need to be more flexible than that...</p> <p>Any thoughts?</p> <p><strong>UPDATE:</strong><br> Dan's comment below answered this problem... This is the code I ended up with for reference;</p> <pre><code>Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged DateTimePicker2.MinDate = Date.Today + DateTimePicker1.Value.TimeOfDay End Sub Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged DateTimePicker1.MaxDate = Date.Today + DateTimePicker2.Value.TimeOfDay End Sub </code></pre> <p>DateTimePIcker1 being the lower bound, DateTImePIcker2 being the upper bound, both using "h:mm tt" as a custom datetime format.</p> <p>Storing these preferences will now just use the Value.TimeOfDay (and be stored as a timespan), then on retrieval the following load process occurs;</p> <pre><code>DateTimePicker1.Value = Date.Today + StoredTimeLowerBound DateTimePicker2.Value = Date.Today + StoredTimeUpperBound </code></pre> <p>This will automatically call the ValueChanged events handled above and restore the selected values.</p> <p>Dan, thanks for your help :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload