Imports System.Collections.Generic
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinSchedule
Imports System.Diagnostics
Public Sub SelectDateTimeRange(ByVal control As UltraTimelineView, ByVal range As DateTimeRange)
' Handle the SelectedDateTimeRangeChanging event
RemoveHandler control.SelectedDateTimeRangeChanging, AddressOf Me.OnSelectedDateTimeRangeChanging
AddHandler control.SelectedDateTimeRangeChanging, AddressOf Me.OnSelectedDateTimeRangeChanging
' If the caller did not specify a range, use the default,
' i.e., the working hour range of the current day.
If range Is Nothing Then
Dim calendarInfo As UltraCalendarInfo = control.CalendarInfo
Dim dow As Infragistics.Win.UltraWinSchedule.DayOfWeek = calendarInfo.DaysOfWeek(DateTime.Today.DayOfWeek)
Dim start As DateTime = DateTime.Today.Add(dow.WorkDayStartTime.TimeOfDay)
Dim _end As DateTime = DateTime.Today.Add(dow.WorkDayEndTime.TimeOfDay).AddSeconds(-1)
range = New DateTimeRange(start, _end)
End If
' Select the range programmatically
control.SelectDateTimeRange(range.StartDateTime, range.EndDateTime)
End Sub
Private Sub OnSelectedDateTimeRangeChanging(ByVal sender As Object, ByVal e As SelectedDateTimeRangeChangingEventArgs)
' If no listeners have canceled the SelectedDateTimeRangeChanging
' event, hook the SelectedDateTimeRangeChanged event so we get a
' notification after it has changed.
If e.Cancel = False Then
Dim control As UltraTimelineView = sender
AddHandler control.SelectedDateTimeRangeChanged, AddressOf Me.OnSelectedDateTimeRangeChanged
End If
End Sub
Private Sub OnSelectedDateTimeRangeChanged(ByVal sender As Object, ByVal e As SelectedDateTimeRangeChangedEventArgs)
' Format the selected date/time range and set the text
' of the label control that is used to display it.
' Adjust the end time if the PrimaryInterval is a TimeInterval,
' so that instead of '9AM - 9:59AM', the user sees '9AM - 10AM'.
Dim control As UltraTimelineView = sender
Dim adjustEndTime As Boolean = (control.PrimaryInterval.GetType() Is GetType(TimeInterval))
Me.lblSelectedRange.Text = DateTimeRange.Format(e.Range.StartDateTime, e.Range.EndDateTime, DateTimeRange.Separator, adjustEndTime)
' Detach the event handler
RemoveHandler control.SelectedDateTimeRangeChanged, AddressOf Me.OnSelectedDateTimeRangeChanged
End Sub