Version

ActionCode Property (KeyActionMapping)

Gets/sets the action code.
Syntax
'Declaration
 
Public Shadows Property ActionCode As UltraWeekViewAction
public new UltraWeekViewAction 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.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