GrapeCity MultiRow Windows Forms Documentation
ShortcutKeyManager Class
Members  Example 


Represents a manager which manages all the ShortcutKey settings for the GcMultiRow control.
Syntax
<DefaultMemberAttribute("Item")>
Public Class ShortcutKeyManager 
Dim instance As ShortcutKeyManager
[DefaultMember("Item")]
public class ShortcutKeyManager 
Remarks

The ShortcutKeyManager has four modes: DefaultMode, DisplayMode, RowMode, and ListBoxMode. They correspond to the GcMultiRow.ViewMode property. Each ViewMode has an individual list of ShortcutKeys. When a key is pressed in the GcMultiRow control, ShortcutKey is searched to see who pressed the key in the corresponding mode list. You can add or remove a ShortcutKey by editing the special list, or by using Register(IAction,Keys) and Unregister(IAction) methods. You can also clear all defined ShortcutKeys with the Clear method, and reset them to the default status with the Reset method.

When a GcMultiRow control is created, some default ShortcutKeys are registered in the individual view mode lists.

You can call the GcMultiRow.ShortcutKeyManager's Clear method to clear the default ShortcutKeys or you can call the Unregister(IAction) method to remove the specific action that you do not need.

You also can write a special action by implementing the IAction interface and registering it in the ShortcutKeyManager to implement your own special logic, or just register the existent actions in SelectionActions, EditingActions, ScrollActions, or ComponentActions.

Example
The following code example shows how to manage GcMultiRow controls shortcut key settings. The example shows how to change a key's action, and how to customize your own action. This code example is part of a larger example provided for the GcMultiRow.ShortcutKeyManager property.
void Form1_Load(object sender, EventArgs e)
        {
            gcMultiRow1.Template = Template.Default;
            gcMultiRow1.RowCount = 5;

            // Register another action to a existent key. Unregister old key first.
            this.gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Enter);
            // Register to new action.
            this.gcMultiRow1.ShortcutKeyManager.Register(new EditThenMoveNextAction(), Keys.Enter);

            // Register an action list. Select all first, and then, copy.
            this.gcMultiRow1.ShortcutKeyManager.Register(new ActionList(SelectionActions.SelectAll, EditingActions.Copy), Keys.Control | Keys.Shift | Keys.C);
        }

        class EditThenMoveNextAction : Action
        {
            public override bool CanExecute(GcMultiRow target)
            {
                return true;
            }

            protected override void OnExecute(GcMultiRow target)
            {
                if (target.IsCurrentCellInEditMode == false && EditingActions.BeginEdit.CanExecute(target))
                {
                    EditingActions.BeginEdit.Execute(target);
                }
                else
                {
                    SelectionActions.MoveToNextCell.Execute(target);
                }
            }
        }
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        gcMultiRow1.Template = Template.Default
        gcMultiRow1.RowCount = 5

        ' Register another action to a existent key. Unregister old key first.
        Me.gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Enter)
        ' Register to new action.
        Me.gcMultiRow1.ShortcutKeyManager.Register(New EditThenMoveNextAction(), Keys.Enter)

        ' Register an action list. Select all first, and then, copy.
        Me.gcMultiRow1.ShortcutKeyManager.Register(New ActionList(SelectionActions.SelectAll, EditingActions.Copy), Keys.Control Or Keys.Shift Or Keys.C)
    End Sub

    Private Class EditThenMoveNextAction
        Inherits Action
        Public Overloads Overrides Function CanExecute(ByVal target As GcMultiRow) As Boolean
            Return True
        End Function

        Protected Overloads Overrides Sub OnExecute(ByVal target As GcMultiRow)
            If target.IsCurrentCellInEditMode = False AndAlso EditingActions.BeginEdit.CanExecute(target) Then
                EditingActions.BeginEdit.Execute(target)
            Else
                SelectionActions.MoveToNextCell.Execute(target)
            End If
        End Sub
    End Class
Inheritance Hierarchy

System.Object
   GrapeCity.Win.MultiRow.ShortcutKeyManager

Requirements

Target Platforms: 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

Reference

ShortcutKeyManager Members
GrapeCity.Win.MultiRow Namespace
ShortcutKey Structure
ShortcutKeyManager Property

 

 


Copyright © GrapeCity, inc. All rights reserved.