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
using System.Collections.Generic; using Infragistics.Win; using Infragistics.Win.UltraWinSchedule; using System.Diagnostics; private void button1_Click(object sender, EventArgs e) { // Create a new DateRecurrence on which the dialog session will be based. DateRecurrence recurrence = 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 RecurrenceDialog dialog = new RecurrenceDialog( recurrence ); dialog.ShowDialog(); // If the dialog session was not canceled... if ( dialog.Result == RecurrenceDialogResult.Ok ) { // 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 List<DateTime> occurrenceDates = new List<DateTime>(10); DateTime startDate = DateTime.Today; while ( occurrenceDates.Count < 10 ) { Nullable<DateTime> nextOccurrence = recurrence.GetDateOfNextOccurrence( startDate ); if ( nextOccurrence.HasValue ) { occurrenceDates.Add( nextOccurrence.Value ); startDate = nextOccurrence.Value.AddDays(1); if ( startDate > recurrence.RangeEndDate ) break; } else break; } // Display a human-readable description of the recurrence // along with the dates of the first 10 occurrences in a MessageBox StringBuilder sb = 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 ); foreach( DateTime occurrenceDate in occurrenceDates ) { sb.AppendLine( occurrenceDate.ToShortDateString() ); } // Show the MessageBox. MessageBox.Show( sb.ToString(), recurrence.ToString(), MessageBoxButtons.OK ); } }