Version

ActionCode Property (KeyActionMapping)

Gets/sets the action code.
Syntax
'Declaration
 
Public Shadows Property ActionCode As UltraMonthViewSingleAction
public new UltraMonthViewSingleAction ActionCode {get; set;}
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.MonthViewSingle

    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, UltraMonthViewSingleAction.ExitEditModeAndSaveChanges, 0, UltraMonthViewSingleState.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.ultraMonthViewSingle1.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.ultraMonthViewSingle1.KeyActionMappings.Add(keyMappingToAdd)
            '	Add an appointment so they can test it out
            Me.ultraMonthViewSingle1.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.ultraMonthViewSingle1.KeyActionMappings.Add(keyMappingToAdd)
            '	Add an appointment so they can test it out
            Me.ultraMonthViewSingle1.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.ultraMonthViewSingle1.KeyActionMappings
            If keyMapping.KeyCode = keyToMap Then Me.ultraMonthViewSingle1.KeyActionMappings.Remove(keyMapping)
        Next

        '	Now we can add the custom mapping
        Me.ultraMonthViewSingle1.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.ultraMonthViewSingle1.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.MonthViewSingle;
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
												 UltraMonthViewSingleAction.ExitEditModeAndSaveChanges,		//	ActionCode
												 0,		//	StateDisallowed
												 UltraMonthViewSingleState.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.ultraMonthViewSingle1.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.ultraMonthViewSingle1.KeyActionMappings.Add( keyMappingToAdd );
				//	Add an appointment so they can test it out
				this.ultraMonthViewSingle1.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.ultraMonthViewSingle1.KeyActionMappings.Add( keyMappingToAdd );
				//	Add an appointment so they can test it out
				this.ultraMonthViewSingle1.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.ultraMonthViewSingle1.KeyActionMappings )
			{
				if ( keyMapping.KeyCode == keyToMap )
					this.ultraMonthViewSingle1.KeyActionMappings.Remove( keyMapping );
			}

			//	Now we can add the custom mapping
			this.ultraMonthViewSingle1.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.ultraMonthViewSingle1.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