Version

OnBeforeSelectedDateRangeChange Method

Raises the BeforeSelectedDateRangeChange event before a DateRange is removed from the SelectedDateRanges collection.
Syntax
'Declaration
 
Protected Overridable Sub OnBeforeSelectedDateRangeChange( _
   ByVal e As BeforeSelectedDateRangeChangeEventArgs _
) 
protected virtual void OnBeforeSelectedDateRangeChange( 
   BeforeSelectedDateRangeChangeEventArgs e
)

Parameters

e
A BeforeSelectedDateRangeChangeEventArgs that provides data for the event.
Remarks

Raising an event invokes the event handler through a delegate.

The OnBeforeSelectedDateRangeChange method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Holidays to Inheritors: When overriding OnBeforeSelectedDateRangeChange in a derived class, be sure to call the base class's OnBeforeSelectedDateRangeChange method so that registered delegates receive the event.

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