Version

BeforeSelectedHolidaysChangeEventHandler Delegate

Delegate for handling the event that occurs before a change occurs to the SelectedHolidays.
Syntax
'Declaration
 
Public Delegate Sub BeforeSelectedHolidaysChangeEventHandler( _
   ByVal sender As Object, _
   ByVal e As BeforeSelectedHolidaysEventArgs _
) 
public delegate void BeforeSelectedHolidaysChangeEventHandler( 
   object sender,
   BeforeSelectedHolidaysEventArgs e
)

Parameters

sender
e
Example
This example compares the old selection to the new selection and displays information to the end user about what has changed. It then prompts to see if they want to continue with the new selection.

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_BeforeSelectedHolidaysChange(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinSchedule.BeforeSelectedHolidaysEventArgs) Handles ultraCalendarInfo1.BeforeSelectedHolidaysChange

        '----------------------------------------------------------------------------------------------------
        '	Description
        '	BeforeSelectedHolidaysChange
        '
        '	Fires after one or more Holiday(s) are selected or deselected.
        '
        '----------------------------------------------------------------------------------------------------

        '	If the count of the NewSelectedHolidays collection is greater than
        '	the count of the existing SelectedHolidays collection, then new
        '	Holidays have been selected
        Dim info As String = String.Empty
        If (e.NewSelectedHolidays.Count > Me.ultraCalendarInfo1.SelectedHolidays.Count) Then
            info += "The following Holidays have been added to the selection:" + vbCrLf + vbCrLf

            If (Me.ultraCalendarInfo1.SelectedHolidays.Count > 0) Then
                '	Iterate the NewSelectedHolidays collection and get information on
                '	each new selection
                Dim newHoliday As Holiday
                For Each newHoliday In e.NewSelectedHolidays

                    '	Iterate the existing selected Holidays, and see which ones are new
                    '	to the collection
                    Dim oldHoliday As Holiday
                    For Each oldHoliday In Me.ultraCalendarInfo1.SelectedHolidays
                        If (newHoliday Is oldHoliday) Then
                            Exit For
                        Else

                            '	If the existing Holiday exists in the SelectedHolidays collection,
                            '	then it is not really new to the user, so we won't list it as new.
                            info += newHoliday.Name + " ("
                            info += newHoliday.StartDate.ToLongDateString() + ")" + vbCrLf
                        End If

                    Next
                Next

            Else
                '	The count of the SelectedHolidays collection was zero, so we don't
                '	have to check to see whether they already existed, just list them all
                Dim newHoliday As Holiday
                For Each newHoliday In e.NewSelectedHolidays
                    '	If the existing Holiday exists in the SelectedHolidays collection,
                    '	but not in the NewSelectedHolidays collection, it has been deselected
                    info += newHoliday.Name + " ("
                    info += newHoliday.StartDate.ToLongDateString() + ")" + vbCrLf
                Next
            End If
        ElseIf (e.NewSelectedHolidays.Count > 0) Then

            '	Otherwise, one or more existing Holidays have been deselected
            info += "The following Holidays have been removed from the selection:" + vbCrLf + vbCrLf

            '	Iterate the existing SelectedHolidays collection and get information on
            '	each selection that is being removed
            Dim oldHoliday As Holiday
            For Each oldHoliday In Me.ultraCalendarInfo1.SelectedHolidays
                '	Iterate the existing selected Holidays, and see which ones are new
                '	to the collection
                Dim newHoliday As Holiday
                For Each newHoliday In e.NewSelectedHolidays
                    If (newHoliday Is oldHoliday) Then
                        Exit For
                    Else

                        '	If the existing Holiday exists in the SelectedHolidays collection,
                        '	but not in the NewSelectedHolidays collection, it has been deselected
                        info += oldHoliday.Name + " ("
                        info += oldHoliday.StartDate.ToLongDateString() + ")" + vbCrLf
                    End If
                Next

            Next
        Else
            '	The selection has been cleared
            info += "The SelectedHolidays collection is about to be cleared." + vbCrLf



            info += vbCrLf + vbCrLf + "Continue?"

            '	Display a MessageBox and prompt the end user to make sure they want to continue
            Dim result As DialogResult = MessageBox.Show(info, "BeforeSelectedHolidaysChange", MessageBoxButtons.YesNo)

            '	If the user does not want to continue, cancel the event
            If (result = DialogResult.No) Then e.Cancel = True
        End If

    End Sub
private void ultraCalendarInfo1_BeforeSelectedHolidaysChange(object sender, Infragistics.Win.UltraWinSchedule.BeforeSelectedHolidaysEventArgs e)
{		

	//----------------------------------------------------------------------------------------------------
	//	Description
	//	BeforeSelectedHolidaysChange
	//
	//	Fires after one or more Holiday(s) are selected or deselected.
	//
	//----------------------------------------------------------------------------------------------------

	//	If the count of the NewSelectedHolidays collection is greater than
	//	the count of the existing SelectedHolidays collection, then new
	//	Holidays have been selected
	string info = string.Empty;
	if ( e.NewSelectedHolidays.Count > this.ultraCalendarInfo1.SelectedHolidays.Count )
	{
		info += "The following Holidays have been added to the selection:" + "\n\n";

		if ( this.ultraCalendarInfo1.SelectedHolidays.Count > 0 )
		{
			//	Iterate the NewSelectedHolidays collection and get information on
			//	each new selection
			foreach( Holiday newHoliday in e.NewSelectedHolidays )
			{
				//	Iterate the existing selected Holidays, and see which ones are new
				//	to the collection
				foreach( Holiday oldHoliday in this.ultraCalendarInfo1.SelectedHolidays )
				{
					if ( newHoliday == oldHoliday )
						continue;
					else
					{
						//	If the existing Holiday exists in the SelectedHolidays collection,
						//	then it is not really new to the user, so we won't list it as new.
						info += newHoliday.Name + " (";
						info += newHoliday.StartDate.ToLongDateString() + ")" + "\n";
					}
				}
				
			}
		}
		else
		{
			//	The count of the SelectedHolidays collection was zero, so we don't
			//	have to check to see whether they already existed, just list them all
			foreach( Holiday newHoliday in e.NewSelectedHolidays )
			{
				info += newHoliday.Name + " (";
				info += newHoliday.StartDate.ToLongDateString() + ")" + "\n";
			}
		}
	}
	else
	if ( e.NewSelectedHolidays.Count > 0 )
	{
		//	Otherwise, one or more existing Holidays have been deselected
		info += "The following Holidays have been removed from the selection:" + "\n\n";

		//	Iterate the existing SelectedHolidays collection and get information on
		//	each selection that is being removed
		foreach( Holiday oldHoliday in this.ultraCalendarInfo1.SelectedHolidays )
		{
			//	Iterate the existing selected Holidays, and see which ones are new
			//	to the collection
			foreach( Holiday newHoliday in e.NewSelectedHolidays )
			{
				if ( newHoliday == oldHoliday )
					continue;
				else
				{
					//	If the existing Holiday exists in the SelectedHolidays collection,
					//	but not in the NewSelectedHolidays collection, it has been deselected
					info += newHoliday.Name + " (";
					info += newHoliday.StartDate.ToLongDateString() + ")" + "\n";
				}

			}
			
		}
	}
	else
	{
		//	The selection has been cleared
		info += "The SelectedHolidays collection is about to be cleared." + "\n";

	}

	info += "\n\n" + "Continue?";

	//	Display a MessageBox and prompt the end user to make sure they want to continue
	DialogResult result = MessageBox.Show( info, "BeforeSelectedHolidaysChange", MessageBoxButtons.YesNo );

	//	If the user does not want to continue, cancel the event
	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