Hello everyone,
I'm using an UltraDateTimeEditor on a form that allows a user to enter a start and end time for an appointment. I'd like to limit what the user can type in the minutes section of the DateTimeEditor (currently using the {date} {time} mask) to increments of 15 minutes. For example, if the user tries to type "16" in the interval, it either wouldn't be allowed and would revert OR would round to either 15 or 30.
Is there currently a way to limit the user's entries in a specified field of the DateTimeEditor? I'd like to have them be able to type for the rest of the fields, just not the minutes, as it needs to be in increments of 15. Only ":00", ":15", ":30", and ":45" would be valid entries.
Any suggestions are greatly appreciated. Thanks!
Hello Medwards11,
We are still following this forum thread.Did you have a chanse to look into the provided sample here in forum thread?
If you have any other questions with this matter please feel free to let us know.
I wasn't able to apply the suggested example to my application, but here's the code I came up with to round the number to the nearest 15 minute interval:
Private Function DetermineMinuteRounding(ByVal currentMinute As Integer) As Integer Dim currentValue = DirectCast(startTimePicker.Value, DateTime) Dim newMinute As Integer = currentMinute
If currentMinute Mod 15 > 0 Then Dim toList As New List(Of Integer)
toList.Add(0) toList.Add(15) toList.Add(30) toList.Add(45) toList.Add(60)
Dim diff = 15
For Each item In toList If (Math.Abs(item - currentMinute) < diff) Then diff = Math.Abs(item - currentMinute) newMinute = item End If Next
End If
If newMinute <> -1 Then Return newMinute Else Return 0 End If
End Function
Private Sub startTimePicker_BeforeExitEditMode(ByVal sender As Object, ByVal e As Infragistics.Win.BeforeExitEditModeEventArgs) Handles startTimePicker.BeforeExitEditMode Dim currentMinute = startTimePicker.DateTime.Minute Dim newMinute = DetermineMinuteRounding(startTimePicker.DateTime.Minute) startTimePicker.Value = startTimePicker.DateTime.AddMinutes(-currentMinute).AddMinutes(newMinute) End Sub
Private Sub endTimePicker_BeforeExitEditMode(ByVal sender As Object, ByVal e As Infragistics.Win.BeforeExitEditModeEventArgs) Handles endTimePicker.BeforeExitEditMode Dim currentMinute = endTimePicker.DateTime.Minute Dim newMinute = DetermineMinuteRounding(endTimePicker.DateTime.Minute) endTimePicker.Value = endTimePicker.DateTime.AddMinutes(-currentMinute).AddMinutes(newMinute) End Sub
It probably isn't the best way to do it, but it's what I'm using and it seems to be achieving desired results.
Thanks for the assistance.
We are glad that you have found a solution for your issue, and thank you for sharing it with the community. If you have any other questions please feel free to let us know.