您参考下下面代码,自定义keymap
- 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();
- }
- }
复制代码 |