Skip to main content Skip to footer

Handling Function Keys in Spread

When F2 and F3 keys are being captured by the SpreadView for processing, they do not get sent to the KeyEvents for the Spread. This happens because Keystrokes processed by the Spread control are divided into one of two groups. One group consists of keystrokes that are processed when the Spread control has focus but not when a cell edit control has focus. These keystrokes are processed in the OnKeyDown and OnKeyPress methods which raise KeyDown and KeyPress events. These keystrokes are listed in the WhenFocused input map. However, the other group consist of keystrokes that are processed when either the Spread control has focus or the cell edit control has focus. These keystrokes are processed in the ProcessDialogKey and ProcessDialogChar methods which do not raise KeyDown and KeyPress events. These keystrokes are listed in the WhenAncestorOfFocused input map. Now, when the cell edit control has focus, the keystroke events (KeyDown, KeyPress, KeyUp) are raised by the cell edit control (not by the Spread control). Hence, in order to capture F2 and F3 keys in KeyDown event, we need to override the default action of these keys in the SpreadView as given below:-



  FarPoint.Win.Spread.InputMap im1;  
  FarPoint.Win.Spread.Keystroke keyF3 = new FarPoint.Win.Spread.Keystroke(Keys.F3, Keys.None, false);  
  im1 = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused);  
  im1.Put(keyF3, FarPoint.Win.Spread.SpreadActions.None);  
  FarPoint.Win.Spread.InputMap im2;  
  FarPoint.Win.Spread.Keystroke keyF4 = new FarPoint.Win.Spread.Keystroke(Keys.F4, Keys.None, false);  
  im2 = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused);  
  im2.Put(keyF4, FarPoint.Win.Spread.SpreadActions.None);  

  void fpSpread1_EditModeOn(object sender, EventArgs e)  
   {  
     System.Windows.Forms.KeyEventHandler KeyDownHandler = fpSpread1_KeyDown;  
     fpSpread1.EditingControl.KeyDown += KeyDownHandler;  
   }  

   void fpSpread1_EditModeOff(object sender, EventArgs e)  
   {  
     System.Windows.Forms.KeyEventHandler KeyDownHandler = fpSpread1_KeyDown;  
     fpSpread1.EditingControl.KeyDown -= KeyDownHandler;  
   }  


Please refer the attached sample below for detailed implementation. Download Sample

MESCIUS inc.

comments powered by Disqus