Spread Silverlight Documentation
GrapeCity.Windows.SpreadSheet.UI Namespace / SpreadAction Delegate
The object to do the action on.
The ActionEventArgs instance that contains the action event data.

In This Topic
    SpreadAction Delegate
    In This Topic
    Represents the action delegate for input maps.
    Public Delegate Sub SpreadAction( _
       ByVal sender As Object, _
       ByVal e As ActionEventArgs _
    Dim instance As New SpreadAction(AddressOf HandlerMethod)
    public delegate void SpreadAction( 
       object sender,
       ActionEventArgs e


    The object to do the action on.
    The ActionEventArgs instance that contains the action event data.
    This example creates a custom action and maps keyboard keys to the action.
    public MainWindow()
                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())))
                    //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;
    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
            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))
        End Sub
    See Also