Imports System.Collections.Generic
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinSchedule
Imports System.Diagnostics
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Create a new DateRecurrence on which the dialog session will be based.
Dim recurrence As DateRecurrence = New DateRecurrence(New DateTime(DateTime.Today.Year, 1, 1))
recurrence.RangeEndDate = New DateTime(DateTime.Today.Year, 12, 31)
' Create and show the RecurrenceDialog in DateRecurrence mode
Dim dialog As New RecurrenceDialog(recurrence)
dialog.ShowDialog()
' If the dialog session was not canceled...
If dialog.Result = RecurrenceDialogResult.Ok Then
' Reassign the 'recurrence' stack variable to now
' reference the instance that resulted from the dialog session.
recurrence = dialog.DateRecurrence
' Get the first 10 occurrences generated by the recurrence
Dim occurrenceDates As List(Of DateTime) = New List(Of DateTime)(10)
Dim startDate As DateTime = DateTime.Today
While occurrenceDates.Count < 10
Dim nextOccurrence As Nullable(Of DateTime) = recurrence.GetDateOfNextOccurrence(startDate)
If nextOccurrence.HasValue Then
occurrenceDates.Add(nextOccurrence.Value)
startDate = nextOccurrence.Value.AddDays(1)
If (startDate > recurrence.RangeEndDate) Then Exit While
Else
Exit While
End If
End While
' Display a human-readable description of the recurrence
' along with the dates of the first 10 occurrences in a MessageBox
Dim sb As New StringBuilder()
sb.AppendLine(recurrence.Description)
sb.AppendLine(Environment.NewLine)
' List the first 10 occurrences
sb.AppendLine(String.Format("The first {0} occurrences are:", occurrenceDates.Count))
sb.AppendLine(Environment.NewLine)
Dim occurrenceDate As DateTime
For Each occurrenceDate In occurrenceDates
sb.AppendLine(occurrenceDate.ToShortDateString())
Next
' Show the MessageBox.
MessageBox.Show(sb.ToString(), recurrence.ToString(), MessageBoxButtons.OK)
End If
End Sub