Spread Silverlight Documentation
SpreadAction Delegate
ExampleExample 


The object to do the action on.
The ActionEventArgs instance that contains the action event data.
Represents the action delegate for input maps.
Syntax
'Declaration
 
Public Delegate Sub SpreadAction( _
   ByVal sender As System.Object, _
   ByVal e As ActionEventArgs _
) 
'Usage
 
Dim instance As New SpreadAction(AddressOf HandlerMethod)
public delegate void SpreadAction( 
   System.object sender,
   ActionEventArgs e
)

Parameters

sender
The object to do the action on.
e
The ActionEventArgs instance that contains the action event data.
Example
This example creates a custom action and maps keyboard keys to the action.
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
Requirements

Target Platforms: Windows 7, Windows 8 Desktop, Windows Vista SP1 or later, Windows Server 2000, Windows 2000 Professional, Windows XP Professional, Windows NT 4.0 Workstation, SP6, Windows NT 4.0 Server, SP6

See Also

Reference

SpreadAction Members
GrapeCity.Windows.SpreadSheet.UI Namespace

 

 


Copyright © GrapeCity, inc. All rights reserved.