Spread WPF Documentation
Using Input Mapping
Spread WPF Documentation > Developer's Guide > Managing the User Interface > Using Input Mapping

You can change the keyboard keys that are used to trigger built-in actions to other keys. Actions include navigation, selection, cut, copy, paste, clear, undo, and redo.

There is a complete list of actions in the SpreadActions class.

Using Code

The following example maps keys to actions.

CS
Copy Code
public MainWindow()
        {
            InitializeComponent();
            Dictionary<GrapeCity.Windows.SpreadSheet.UI.KeyStroke, GrapeCity.Windows.SpreadSheet.UI.SpreadAction> keyMap = gcSpreadSheet1.View.KeyMap;
            keyMap.Add(new GrapeCity.Windows.SpreadSheet.UI.KeyStroke(Key.OemPlus, ModifierKeys.Alt), new GrapeCity.Windows.SpreadSheet.UI.SpreadAction(OnInsertSumFormula));
            keyMap.Add(new GrapeCity.Windows.SpreadSheet.UI.KeyStroke(Key.B, ModifierKeys.Alt), new GrapeCity.Windows.SpreadSheet.UI.SpreadAction(GrapeCity.Windows.SpreadSheet.UI.SpreadActions.NavigationLeft));
            keyMap.Add(new GrapeCity.Windows.SpreadSheet.UI.KeyStroke(Key.A, ModifierKeys.Alt), new GrapeCity.Windows.SpreadSheet.UI.SpreadAction(GrapeCity.Windows.SpreadSheet.UI.SpreadActions.Clear));
           
        }
        private void OnInsertSumFormula(GrapeCity.Windows.SpreadSheet.UI.SheetView sheet)
        {
            int r = sheet.Worksheet.ActiveRowIndex;
            int c = sheet.Worksheet.ActiveColumnIndex;
            if (r > 0)
            {
                int rStart = r - 1;
                System.ComponentModel.TypeConverter doubleConverter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(double));
                while (rStart > 0)
                {
                    object val = sheet.Worksheet.Cells[rStart, c].Value;
                    if (val is double || val is float || val is long || val is int || val is short || val is byte ||
                      (val != null && doubleConverter.CanConvertFrom(val.GetType())))
                        rStart--;
                }
                //Type numbers in a few cells in a column and type Alt + equal in the cell below them.
               //Hit enter to see the formula update.
                string formula = "SUM(" + sheet.Worksheet.Cells[rStart, c, r - 1, c].ToString() + ")";
                sheet.Worksheet.Cells[r, c].Formula = formula;
                sheet.StartCellEditing();
            }
        }
VB.NET
Copy Code
Private Sub OnInsertSumFormula(sheet As GrapeCity.Windows.SpreadSheet.UI.SheetView)
        Dim r As Integer = sheet.Worksheet.ActiveRowIndex
        Dim c As Integer = sheet.Worksheet.ActiveColumnIndex
        If r > 0 Then
            Dim rStart As Integer = r - 1
            Dim doubleConverter As System.ComponentModel.TypeConverter = System.ComponentModel.TypeDescriptor.GetConverter(GetType(Double))
            While rStart > 0
                Dim val As Object = sheet.Worksheet.Cells(rStart, c).Value
                If TypeOf val Is Double OrElse TypeOf val Is Single OrElse TypeOf val Is Long OrElse TypeOf val Is Integer OrElse TypeOf val Is Short OrElse TypeOf val Is Byte OrElse (val IsNot Nothing AndAlso doubleConverter.CanConvertFrom(val.[GetType]())) Then
                    rStart -= 1
                End If
            End While
            'Type numbers in a few cells in a column and type Alt + equal in the cell below them.
            'Hit enter to see the formula update.
            Dim formula As String = "SUM(" & sheet.Worksheet.Cells(rStart, c, r - 1, c).ToString() & ")"
            sheet.Worksheet.Cells(r, c).Formula = formula
            sheet.StartCellEditing()
        End If
    End Sub
    Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        Dim keyMap As Dictionary(Of GrapeCity.Windows.SpreadSheet.UI.KeyStroke, GrapeCity.Windows.SpreadSheet.UI.SpreadAction) = GcSpreadSheet1.View.KeyMap
        keyMap.Add(New GrapeCity.Windows.SpreadSheet.UI.KeyStroke(Key.OemPlus, ModifierKeys.Alt), New GrapeCity.Windows.SpreadSheet.UI.SpreadAction(AddressOf OnInsertSumFormula))
        keyMap.Add(New GrapeCity.Windows.SpreadSheet.UI.KeyStroke(Key.B, ModifierKeys.Alt), New GrapeCity.Windows.SpreadSheet.UI.SpreadAction(AddressOf GrapeCity.Windows.SpreadSheet.UI.SpreadActions.NavigationLeft))
        keyMap.Add(New GrapeCity.Windows.SpreadSheet.UI.KeyStroke(Key.A, ModifierKeys.Alt), New GrapeCity.Windows.SpreadSheet.UI.SpreadAction(AddressOf GrapeCity.Windows.SpreadSheet.UI.SpreadActions.Clear))
        GcSpreadSheet1.Invalidate()
    End Sub
See Also