Imports Infragistics.Win
Imports Infragistics.Win.UltraWinSchedule
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
' Set the UltraMonthViewMulti control's UseAlternateSelectedDateRanges
' property to true so that when dates are selected, the UltraDayView,
' UltraWeekView, and UltraMonthViewSingle controls do NOT automatically
' reflect those changes.
Me.ultraMonthViewMulti1.UseAlternateSelectedDateRanges = True
' Set the UltraCalendarInfo's AlternateSelectTypeDay property to 'Extended'
' so that multiple days can be selected in the alternate collection, and
' restrict the total number of days that can be selected in the alternate
' collection to 31.
Me.ultraCalendarInfo1.AlternateSelectTypeDay = SelectType.Extended
Me.ultraCalendarInfo1.MaxSelectedDays = 31
End Sub
Private Sub ultraCalendarInfo1_AfterAlternateSelectedDateRangeChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles ultraCalendarInfo1.AfterAlternateSelectedDateRangeChange
' Resume painting for the UltraDayView, UltraWeekView, and
' UltraMonthViewSingle controls.
Me.ultraDayView1.EndUpdate()
Me.ultraWeekView1.EndUpdate()
Me.ultraMonthViewSingle1.EndUpdate()
If (Me.ultraDayView1.Visible) Then
Me.ultraDayView1.Refresh()
ElseIf (Me.ultraWeekView1.Visible) Then
Me.ultraWeekView1.Refresh()
ElseIf (Me.ultraMonthViewSingle1.Visible) Then
Me.ultraMonthViewSingle1.Refresh()
End If
End Sub
Private Sub ultraCalendarInfo1_BeforeAlternateSelectedDateRangeChange(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinSchedule.BeforeSelectedDateRangeChangeEventArgs) Handles ultraCalendarInfo1.BeforeAlternateSelectedDateRangeChange
Dim selection As SelectedDateRanges = e.NewSelectedDateRanges
' Get the total number of days that were selected.
Dim totalDaysSelected As Integer = selection.SelectedDaysCount
' Return if nothing was selected.
If totalDaysSelected = 0 Then Return
' Suspend painting for the UltraDayView, UltraWeekView, and
' UltraMonthViewSingle controls while we process the change
' in date selection.
Me.ultraDayView1.BeginUpdate()
Me.ultraWeekView1.BeginUpdate()
Me.ultraMonthViewSingle1.BeginUpdate()
' Determine whether we have a discontiguous selection...since the
' AlternateSelectedDateRanges collection automatically handles
' defragmentation of contiguous selected days, the count of the collection
' will only exceed one if all selected days cannot be expressed by one
' DateRange object.
Dim isDiscontiguous As Boolean = selection.Count > 1
' Get the first and last dates in the date selection.
Dim firstDateInSelection As DateTime = DateTime.MinValue
Dim lastDateInSelection As DateTime = DateTime.MaxValue
Dim i As Integer
For i = 0 To selection.Count - 1
Dim dateRange As DateRange = selection(i)
If i = 0 Then firstDateInSelection = DateRange.StartDate
If i = (selection.Count - 1) Then lastDateInSelection = dateRange.EndDate
Next
' Determine whether the first day of the week is the first day in the selection
Dim firstDayOfWeekBeginsSelection As Boolean = firstDateInSelection.DayOfWeek = Me.ultraCalendarInfo1.FirstDayOfWeek Or Me.ultraCalendarInfo1.FirstDayOfWeek = FirstDayOfWeek.Default
' Analyze the selection and determine which schedule control should be displayed.
Dim controlToDisplay As UltraScheduleControlBase = Me.ultraMonthViewSingle1
If totalDaysSelected <= 14 Then
controlToDisplay = Me.ultraDayView1
If firstDayOfWeekBeginsSelection Then
If (totalDaysSelected = 7) Then controlToDisplay = Me.ultraWeekView1
If (totalDaysSelected = 14) Then controlToDisplay = Me.ultraMonthViewSingle1
End If
End If
If controlToDisplay Is Me.ultraMonthViewSingle1 Then
Me.ultraMonthViewSingle1.VisibleWeeks = totalDaysSelected / 7
ElseIf controlToDisplay Is Me.ultraDayView1 Then
Me.ultraDayView1.CalendarInfo.SelectedDateRanges.Clear()
For i = 0 To selection.Count - 1
Dim dateRange As DateRange = selection(i)
Me.ultraDayView1.CalendarInfo.SelectedDateRanges.Add(dateRange.StartDate, dateRange.EndDate)
Next
End If
Me.DisplayScheduleControl(controlToDisplay)
End Sub
Private Sub DisplayScheduleControl(ByVal control As UltraScheduleControlBase)
Me.ultraDayView1.Visible = False
Me.ultraWeekView1.Visible = False
Me.ultraMonthViewSingle1.Visible = False
control.Visible = True
control.Dock = DockStyle.Fill
End Sub