Version

KeyActionMappings Property (UltraWeekView)

Syntax
'Declaration
 
Public ReadOnly Property KeyActionMappings As KeyActionMappings
public KeyActionMappings KeyActionMappings {get;}
Remarks

By default, the KeyActionMappings collection contains all of the standard keyboard mappings for the UltraWeekView control.

Individual Infragistics.Win.UltraWinSchedule.WeekView.KeyActionMapping objects can be added to and removed from this collection, but caution should be exercised when doing so.

The KeyActionMappings collection offers virtually unlimited freedom of control over the UltraWeekView control's keyboard handling capabilities.

If the default behavior for a particular keystroke does not provide the desired functionality, it can be replaced with a custom Infragistics.Win.UltraWinSchedule.WeekView.KeyActionMapping.

The KeyActionMappings collection is accessed by the control each time a relevant keystroke is received to determine what, if any, action should be attempted.

The following example illustrates the sequence of events that occur when the control receives a keystroke that has significance in the KeyActionMappings table:

Example: The user presses the down arrow key while the control's first visible day is active:

  1. The control's OnKeyDown method is called as a result of the left arrow key being pressed.
  2. The KeyActionMappings table is searched to determine whether there is an action mapped to the down arrow key.
  3. An action is found; in this case, it is the NextDay action.
  4. The control's CurrentState property is queried, to make sure that the control is currently in the state required by the Infragistics.Win.UltraWinSchedule.WeekView.KeyActionMapping object corresponding to the keystroke.
  5. The control's CurrentState property is also queried to make sure that the control is not currently in a state that is disallowed by the Infragistics.Win.UltraWinSchedule.WeekView.KeyActionMapping object corresponding to the keystroke.
  6. The state of the special keys (ALT, CTRL and SHIFT) is checked against the Infragistics.Win.UltraWinSchedule.WeekView.KeyActionMapping object corresponding to the keystroke, as these keys (or a combination thereof) might be required or disallowed by the Infragistics.Win.UltraWinSchedule.WeekView.KeyActionMapping object corresponding to the keystroke.
  7. Assuming all of the required and disallowed criteria were met, the action is then performed by calling the control's PerformAction(UltraWeekViewAction,Boolean,Boolean) method.

The following table lists the default key mappings for the UltraWeekView control:

KeyCode ActionCode StateRequired StateDisallowed SpecialKeysRequired SpecialKeysDisallowed
Down NextDay Day, NextDayIsInMinMaxRange ActivityInEditMode Alt
Up PreviousDay Day, PreviousDayIsInMinMaxRange ActivityInEditMode Alt
Right DayToTheRight Day ActivityInEditMode Alt
Left DayToTheLeft Day ActivityInEditMode Alt
Home FirstDayInWeek Day DayFirst, ActivityInEditMode Alt
End LastDayInWeek Day ActivityInEditMode Alt
Prior ScrollUpByLargeChange Day ActivityInEditMode Alt
Next ScrollDownByLargeChange Day ActivityInEditMode Alt
Tab NextActivityByTab Day AltShift
Tab PreviousActivityByTab Day Shift Alt
Space ToggleDaySelection Day ActivityInEditMode Ctrl AltShift
F2 EnterEditMode Day ActivityInEditMode, ActivityIsLocked All
Escape ExitEditModeAndCancelChanges ActivityInEditMode All
Enter DisplayAppointmentDialog PivotItemIsActivity, SelectedAppointments, AutoAppointmentDialogEnabled ActivityInEditMode, PivotItemIsDay All
Enter ExitEditModeAndSaveChanges ActivityInEditMode NoteInEditMode All
Enter AddNewAppointment Day, NoSelectedActivities ActivityInEditMode All
Delete RemoveSelectedActivities PivotItemIsActivity ActivityInEditMode, PivotItemIsDay All

Example
Demonstrates how to customize the control's KeyActionMappings collection so that a non-default keystroke can be assigned to perform an application-specific action. This example adds a KeyActionMapping for the F2 key which exits edit mode on an Appointment or Note, saving any changes that were made. It also prompts the user to decide whether they want to remove existing mappings for that key.

Imports Infragistics.Win
Imports Infragistics.Win.UltraWinSchedule
Imports Infragistics.Win.UltraWinSchedule.WeekView

    Private Sub CustomizeKeyActionMappings()

        '	Create a new KeyActionMapping object, which we will add to
        '	the control's KeyActionMappings collection. The new KeyActionMapping
        '	object will have the following property settings:
        '
        '	KeyCode = F2
        '	ActionCode = ExitEditModeAndSaveChanges
        '	StateDisallowed = 0 (no disallowed state)
        '	StateRequired = ActivityInEditMode
        '	SpecialKeysDisallowed = All (disallow the action if either Alt, Ctrl, or Shift is pressed)
        '	SpecialKeysRequired = 0 (no special keys required to perform the action)
        '
        Dim keyToMap As Keys = Keys.F2

        Dim keyMappingToAdd As New KeyActionMapping(keyToMap, UltraWeekViewAction.ExitEditModeAndSaveChanges, 0, UltraWeekViewState.ActivityInEditMode, SpecialKeys.All, 0)

        '	Let's display a MessageBox with the properties of the KeyActionMapping
        '	before adding it to the collection, to make sure the user wants to add it.
        Dim msg As String = "The following KeyActionMapping will be added to the KeyActionMappings collection:" + vbCrLf + vbCrLf
        msg += "The keystoke the action will respond to is: " + keyMappingToAdd.KeyCode.ToString() + vbCrLf
        msg += "The action that will be performed when the key is pressed is: " + keyMappingToAdd.ActionCode.ToString() + vbCrLf
        msg += "The disallowed state for the action is (zero indicates no disallowed state): " + keyMappingToAdd.StateDisallowed.ToString() + vbCrLf
        msg += "The required state for the action is (zero indicates no required state): " + keyMappingToAdd.StateRequired.ToString() + vbCrLf
        msg += "The action will not be performed if any of the following special keys are pressed (zero indicates no special keys are disallowed): " + keyMappingToAdd.SpecialKeysDisallowed.ToString() + vbCrLf
        msg += "The action will only be performed if all of the following special keys are pressed (zero indicates no special keys are required): " + keyMappingToAdd.SpecialKeysRequired.ToString() + vbCrLf
        msg += vbCrLf + "Are you sure you want to add the custom KeyActionMapping?" + vbCrLf

        '	Show the message box
        Dim result As DialogResult = MessageBox.Show(msg, "Add KeyActionMapping", MessageBoxButtons.YesNo)

        '	If the user answers No, return, leaving the default KeyActionMappings unaffected
        If result = DialogResult.No Then Return

        '	We will add the KeyActionMapping to the control's KeyActionMappings collection, but before we do, let's see if the user wants to remove any existing ones for that keystroke
        '			
        '	Iterate the KeyActionMappings collection and get a count on the number of existing mappings for the given keystroke
        '
        '	While were are iterating this collection, let's build a string that lists
        '	the actions mapped to the given keystroke, so we can display them
        '	to the user to help them decide whether they want to remove them.
        Dim count As Integer = 0
        Dim mapList As String = String.Empty
        Dim keyMapping As KeyActionMapping
        For Each keyMapping In Me.ultraWeekView.KeyActionMappings
            If keyMapping.KeyCode = keyToMap Then
                count += 1
                mapList += keyMapping.ActionCode.ToString() + vbCrLf
            End If
        Next

        '	If there were none, there is no point in prompting the user, so add the
        '	custom mapping and return
        If count = 0 Then
            Me.ultraWeekView.KeyActionMappings.Add(keyMappingToAdd)
            '	Add an appointment so they can test it out
            Me.ultraWeekView.CalendarInfo.Appointments.Add(DateTime.Now, DateTime.Now.AddMinutes(30), "My Appointment")
            Return
        End If

        '	Notify the user that there are existing mappings, and see if they want to remove them
        msg = "The KeyActionMappings collection already contains the following mappings for " + keyToMap.ToString() + ":" + vbCrLf + vbCrLf
        msg += mapList + vbCrLf
        msg += "Do you want to remove the existing mappings for " + keyToMap.ToString() + "?"

        '	Show the message box
        result = MessageBox.Show(msg, "Remove existing KeyActionMappings", MessageBoxButtons.YesNo, MessageBoxIcon.Information)

        '	If the user answers No, return, leaving the existing KeyActionMappings collection unaffected
        If result = DialogResult.No Then
            Me.ultraWeekView.KeyActionMappings.Add(keyMappingToAdd)
            '	Add an appointment so they can test it out
            Me.ultraWeekView.CalendarInfo.Appointments.Add(DateTime.Now, DateTime.Now.AddMinutes(30.0F), "My Appointment")
            Return
        End If

        '	Remove all KeyActionMappings whose KeyCode property is set to the key we are mapping
        For Each keyMapping In Me.ultraWeekView.KeyActionMappings
            If keyMapping.KeyCode = keyToMap Then Me.ultraWeekView.KeyActionMappings.Remove(keyMapping)
        Next

        '	Now we can add the custom mapping
        Me.ultraWeekView.KeyActionMappings.Add(keyMappingToAdd)

        '	Notify the user that all other mappings were removed
        msg = "All existing mappings for " + keyToMap.ToString() + " successfully removed." + vbCrLf
        MessageBox.Show(msg, "Remove existing KeyActionMappings", MessageBoxButtons.OK)

        '	Add an appointment so they can test it out
        Me.ultraWeekView.CalendarInfo.Appointments.Add(DateTime.Now, DateTime.Now.AddMinutes(30.0F), "My Appointment")

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

		private void CustomizeKeyActionMappings()
		{

			//	Create a new KeyActionMapping object, which we will add to
			//	the control's KeyActionMappings collection. The new KeyActionMapping
			//	object will have the following property settings:
			//
			//	KeyCode = F2
			//	ActionCode = ExitEditModeAndSaveChanges
			//	StateDisallowed = 0 (no disallowed state)
			//	StateRequired = ActivityInEditMode
			//	SpecialKeysDisallowed = All (disallow the action if either Alt, Ctrl, or Shift is pressed)
			//	SpecialKeysRequired = 0 (no special keys required to perform the action)
			//
			Keys keyToMap = Keys.F2;
			KeyActionMapping keyMappingToAdd =
				new KeyActionMapping( keyToMap,	//	KeyCode
												 UltraWeekViewAction.ExitEditModeAndSaveChanges,		//	ActionCode
												 0,		//	StateDisallowed
												 UltraWeekViewState.ActivityInEditMode,		//	StateRequired
												 SpecialKeys.All,	//	SpecialKeysDisallowed
												 0 		//	SpecialKeysRequired
												);
			
			//	Let's display a MessageBox with the properties of the KeyActionMapping
			//	before adding it to the collection, to make sure the user wants to add it.
			string msg = "The following KeyActionMapping will be added to the KeyActionMappings collection:\n\n";
			msg += "The keystoke the action will respond to is: " + keyMappingToAdd.KeyCode.ToString() + "\n";
			msg += "The action that will be performed when the key is pressed is: " + keyMappingToAdd.ActionCode.ToString() + "\n";
			msg += "The disallowed state for the action is (zero indicates no disallowed state): " + keyMappingToAdd.StateDisallowed.ToString() + "\n";
			msg += "The required state for the action is (zero indicates no required state): " + keyMappingToAdd.StateRequired.ToString() + "\n";
			msg += "The action will not be performed if any of the following special keys are pressed (zero indicates no special keys are disallowed): " + keyMappingToAdd.SpecialKeysDisallowed.ToString() + "\n";
			msg += "The action will only be performed if all of the following special keys are pressed (zero indicates no special keys are required): " + keyMappingToAdd.SpecialKeysRequired.ToString() + "\n";
			msg += "\nAre you sure you want to add the custom KeyActionMapping?\n";

			//	Show the message box
			DialogResult result = MessageBox.Show( msg, "Add KeyActionMapping", MessageBoxButtons.YesNo );

			//	If the user answers No, return, leaving the default KeyActionMappings unaffected
			if ( result == DialogResult.No )
				return;

			//	We will add the KeyActionMapping to the control's KeyActionMappings collection, but before we do, let's see if the user wants to remove any existing ones for that keystroke
			//	Iterate the KeyActionMappings collection and get a count on the number of existing mappings for the given keystroke
			//	While were are iterating this collection, let's build a string that lists the actions mapped to the given keystroke, so we can display them to the user to help them decide whether they want to remove them.
			int count = 0;
			string mapList = string.Empty;
			foreach( KeyActionMapping keyMapping in this.ultraWeekView.KeyActionMappings )
			{
				if ( keyMapping.KeyCode == keyToMap )
				{
					count ++;
					mapList += keyMapping.ActionCode.ToString() + "\n";

				}
			}

			//	If there were none, there is no point in prompting the user, so add the
			//	custom mapping and return
			if ( count == 0 )
			{
				this.ultraWeekView.KeyActionMappings.Add( keyMappingToAdd );
				//	Add an appointment so they can test it out
				this.ultraWeekView.CalendarInfo.Appointments.Add( DateTime.Now, DateTime.Now.AddMinutes( 30.0F ), "My Appointment" );
				return;
			}

			//	Notify the user that there are existing mappings, and see if they want to remove them
			msg = "The KeyActionMappings collection already contains the following mappings for " + keyToMap.ToString() + ":\n\n";
			msg += mapList + "\n";
			msg += "Do you want to remove the existing mappings for " + keyToMap.ToString() + "?";

			//	Show the message box
			result = MessageBox.Show( msg, "Remove existing KeyActionMappings", MessageBoxButtons.YesNo, MessageBoxIcon.Information );

			//	If the user answers No, return, leaving the existing KeyActionMappings collection unaffected
			if ( result == DialogResult.No )
			{
				this.ultraWeekView.KeyActionMappings.Add( keyMappingToAdd );
				//	Add an appointment so they can test it out
				this.ultraWeekView.CalendarInfo.Appointments.Add( DateTime.Now, DateTime.Now.AddMinutes( 30.0F ), "My Appointment" );
				return;
			}

			//	Remove all KeyActionMappings whose KeyCode property is set to the key we are mapping
			foreach( KeyActionMapping keyMapping in this.ultraWeekView.KeyActionMappings )
			{
				if ( keyMapping.KeyCode == keyToMap )
					this.ultraWeekView.KeyActionMappings.Remove( keyMapping );
			}

			//	Now we can add the custom mapping
			this.ultraWeekView.KeyActionMappings.Add( keyMappingToAdd );

			//	Notify the user that all other mappings were removed
			msg = "All existing mappings for " + keyToMap.ToString() + " successfully removed.\n";
			MessageBox.Show( msg, "Remove existing KeyActionMappings", MessageBoxButtons.OK );

			//	Add an appointment so they can test it out
			this.ultraWeekView.CalendarInfo.Appointments.Add( DateTime.Now, DateTime.Now.AddMinutes( 30.0F ), "My Appointment" );

		}
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