Articles in this section

How to capture function keys when the current cell is in active edit mode in WinForms GridControl?

Handle the control key

When the grid cell is not actively edited, the grid itself gets these keystrokes. In this case, you can use event handlers like grid.CurrentCellKeyDown and grid.KeyDown to catch the keys. When the current cell is actively being edited, the grid does not automatically catch these keys.

 

Solution

When the current cell is actively being edited, you can use the grid.CurrentCellControlKeyMessage to catch the function keys.

//subscribe to the event
this.gridDataBoundGrid1.CurrentCellControlKeyMessage += new    GridCurrentCellControlKeyMessageEventHandler(grid_CurrentCellControlKeyMessage);

private void grid_CurrentCellControlKeyMessage(object sender, GridCurrentCellControlKeyMessageEventArgs e)
{
   Keys keyCode = (Keys)((int)e.Msg.WParam) & Keys.KeyCode;

   //To view the result in output screen.
   Console.WriteLine(keyCode);
   Console.WriteLine(e.Msg);

   //To display the key pressed.
   MessageBox.Show(keyCode.ToString() + " is pressed");
}
'subscribe to the event
AddHandler Me.gridDataBoundGrid1.CurrentCellControlKeyMessage, AddressOf grid_CurrentCellControlKeyMessage

Private Sub grid_CurrentCellControlKeyMessage(ByVal sender As Object, ByVal e As GridCurrentCellControlKeyMessageEventArgs)
   Dim keyCode As Keys = CType(CInt(Fix(e.Msg.WParam)), Keys) And Keys.KeyCode

   'To view the result in output screen.
   Console.WriteLine(keyCode)
   Console.WriteLine(e.Msg)

   'To display the key pressed.
   MessageBox.Show(keyCode.ToString() & " is pressed")
End Sub

The screenshot below displays the keypress event in edit mode.

 

Control key handled in cell edit mode


Figure
1: control key handled in cell edit mode.

Samples:

C#: FunctionKeyCapture-C#.

VB: FunctionKeyCapture-VB.


Conclusion

I hope you enjoyed learning about how to capture function keys when the current cell is in active edit mode in WinForms GridControl.


You can refer to our WinForms GridControl feature tour page to know about its other groundbreaking feature representations and WinForms GridControl documentation, and how to quickly get started for configuration specifications.


For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.


If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied