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