Spread WPF Documentation
KeyStroke Constructor(Key,ModifierKeys)
Example 


GrapeCity.Windows.SpreadSheet.UI Namespace > KeyStroke Structure > KeyStroke Constructor : KeyStroke Constructor(Key,ModifierKeys)
The key code defined by this KeyStroke structure.
The modifier keys defined by this KeyStroke structure.
Initializes a new instance of the KeyStroke structure with the specified System.Windows.Input.Key and System.Windows.Input.ModifierKeys.
Syntax
'Declaration
 
Public Function New( _
   ByVal keyCode As System.Windows.Input.Key, _
   ByVal modifiers As System.Windows.Input.ModifierKeys _
)
'Usage
 
Dim keyCode As System.Windows.Input.Key
Dim modifiers As System.Windows.Input.ModifierKeys
 
Dim instance As New KeyStroke(keyCode, modifiers)
public KeyStroke( 
   System.Windows.Input.Key keyCode,
   System.Windows.Input.ModifierKeys modifiers
)

Parameters

keyCode
The key code defined by this KeyStroke structure.
modifiers
The modifier keys defined by this KeyStroke structure.
Example
This example maps keys to actions.
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();
            }
        }
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

Reference

KeyStroke Structure
KeyStroke Members
Overload List