Version

BeforeSelectedDateRangeChange Event

Fired before a change is made to the SelectedDateRanges collection.
Syntax
'Declaration
 
Public Event BeforeSelectedDateRangeChange As BeforeSelectedDateRangeChangeEventHandler
public event BeforeSelectedDateRangeChangeEventHandler BeforeSelectedDateRangeChange
Event Data

The event handler receives an argument of type BeforeSelectedDateRangeChangeEventArgs containing data related to this event. The following BeforeSelectedDateRangeChangeEventArgs properties provide information specific to this event.

PropertyDescription
Cancel (Inherited from System.ComponentModel.CancelEventArgs) 
DisplayMaxSelectedDaysErrorMsg Determines if the MaxSelectedDaysError dialog is displayed to the user.
NewSelectedDateRanges Returns a SelectedDateRanges object containing the date ranges that will be selected if the event is not cancelled. The property is read-only.
WasMaxSelectedDaysExceeded Indicates if the max selected items would have been exceeded by the selection change.
Remarks

The BeforeSelectedDateRangeChange event may be canceled (by setting the System.ComponentModel.CancelEventArgs.Cancel property to true) to prevent the SelectedDateRanges collection from changing.

The BeforeSelectedDateRangeChangeEventArgs.NewSelectedDateRanges property returns a collection of the new selected DateRange objects.

The BeforeSelectedDateRangeChangeEventArgs.WasMaxSelectedDaysExceeded property indicates whether the selection change would have been exceeded. When this is true, the BeforeSelectedDateRangeChangeEventArgs.DisplayMaxSelectedDaysErrorMsg property will be used to determine whether a dialog should be displayed to the user to indicate that the MaxSelectedDays property would have been exceeded.

While the event is being invoked, the SelectedHolidays collection cannot be modified. However, the collection returned from the BeforeSelectedDateRangeChangeEventArgs.NewSelectedDateRanges property may be modified.

Example
This example uses the BeforeSelectedDateRangeChangeEventArgs' WasMaxSelectedDaysExceeded property to determine if the limit on selected days has been reached if it has, the limit is incremented. It also checks the new selection to determine whether the selection includes a weekend day and if it does, the user is prompted.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinSchedule
Imports System.Diagnostics

    Private Sub ultraCalendarInfo1_BeforeSelectedDateRangeChange(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinSchedule.BeforeSelectedDateRangeChangeEventArgs) Handles ultraCalendarInfo1.BeforeSelectedDateRangeChange

        '----------------------------------------------------------------------------------------------------
        '	Description
        '	BeforeSelectedDateRangeChange
        '
        '	Fires before a range of days is selected or deselected.
        '
        '	The SelectedDateRanges collection is actually a collection of collections,
        '	each "sub collection" representing the actual days that are selected. Each
        '	DateRange object represents a contiguous range of days that are all selected.
        '	When new days are selected, they are added to an existing DateRange object,
        '	if the new day is adjacent to a currently selected day. If it is not, a new DateRange
        '	object is added to the collection, which will at that point have only one day in it.
        '
        '----------------------------------------------------------------------------------------------------

        '	If the limit on the number of selected days has been reached,
        '	suppress the dialog, and up the limit by one
        If (e.WasMaxSelectedDaysExceeded) Then
            Me.ultraCalendarInfo1.MaxSelectedDays += 1
            e.DisplayMaxSelectedDaysErrorMsg = False
        End If

        Dim range As Infragistics.Win.UltraWinSchedule.DateRange
        For Each range In e.NewSelectedDateRanges
            Dim day As Infragistics.Win.UltraWinSchedule.Day
            For Each day In range.Days

                If day.DayOfWeek.DayOfTheWeek = System.DayOfWeek.Saturday Or day.DayOfWeek.DayOfTheWeek = System.DayOfWeek.Sunday Then

                    Dim info As String = "The new selection includes a weekend day." + vbCrLf
                    info += "Continue?." + vbCrLf
                    Dim result As DialogResult = MessageBox.Show(info, "BeforeSelectedDateRangeChange", MessageBoxButtons.YesNo)
                    If (result = DialogResult.No) Then
                        e.Cancel = True
                    End If
                End If
            Next
        Next

    End Sub
using System.Diagnostics;
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinSchedule;

		private void ultraCalendarInfo1_BeforeSelectedDateRangeChange(object sender, Infragistics.Win.UltraWinSchedule.BeforeSelectedDateRangeChangeEventArgs e)
		{

			//----------------------------------------------------------------------------------------------------
			//	Description
			//	BeforeSelectedDateRangeChange
			//
			//	Fires before a range of days is selected or deselected.
			//
			//	The SelectedDateRanges collection is actually a collection of collections,
			//	each "sub collection" representing the actual days that are selected. Each
			//	DateRange object represents a contiguous range of days that are all selected.
			//	When new days are selected, they are added to an existing DateRange object,
			//	if the new day is adjacent to a currently selected day. If it is not, a new DateRange
			//	object is added to the collection, which will at that point have only one day in it.
			//
			//----------------------------------------------------------------------------------------------------
		
			//	If the limit on the number of selected days has been reached,
			//	suppress the dialog, and up the limit by one
			if ( e.WasMaxSelectedDaysExceeded )
			{
				this.ultraCalendarInfo1.MaxSelectedDays++;
				e.DisplayMaxSelectedDaysErrorMsg = false;
			}

			foreach ( DateRange range in e.NewSelectedDateRanges )
			{
				foreach( Infragistics.Win.UltraWinSchedule.Day day in range.Days )
				{
					if ( (System.DayOfWeek)day.DayOfWeek.DayOfTheWeek == System.DayOfWeek.Saturday ||
						 (System.DayOfWeek)day.DayOfWeek.DayOfTheWeek == System.DayOfWeek.Sunday )
					{
						string info = "The new selection includes a weekend day." + "\n";
						info += "Continue?." + "\n";
						DialogResult result = MessageBox.Show( info, "BeforeSelectedDateRangeChange", MessageBoxButtons.YesNo );
						if ( result == DialogResult.No )
							e.Cancel = true;
					}
				}
			}

		}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also