ReoGrid Forum

Fast and powerful .NET Spreadsheet Component

You are not logged in.

Announcement

This forum has been archived and no longer accepts new user registrations. Please report your questions, problems, and feedback to the issue page of ReoGrid on GitHub. Thank you for your cooperation.

https://github.com/unvell/ReoGrid/issues

#1 2015-03-23 06:19:04

James
Member
Registered: 2015-03-23
Posts: 5

Keyboard Events

I am having trouble with the detection of the keyboard events.  There are no problems with the code for CellMouseEventArgs, eg. CellMouseMove.
Your guidance will be appreciated please regarding the BeforeCellKeyDown, AfterCellKeyDown and the CellKeyUp events.  Otherwise, the Grid control functions very well for me, thank-you.

Imports unvell.ReoGrid
Imports unvell.ReoGrid.Events

Sub Form1_Load ....
 Dim WSheet = MyGrid.CurrentWorksheet
 AddHandler WSheet.CellMouseMove, AddressOf Grid_CellMouseMove
 AddHandler WSheet.CellKeyUp, AddressOf GSheet_CellKeyUp
End Sub

 Private Sub Grid_CellMouseMove(ByVal sender As Object, ByVal e As CellMouseEventArgs)
'  No problems here
     Dim msXY As ReoGridPos = e.CellPosition
     ....
 End Sub

 Private Sub GSheet_CellKeyUp(ByVal sender As Object, ByVal e As CellKeyDownEventArgs)
'  Does not work
    MessageBox.Show("Worked?", " ", MessageBoxButtons.OK, MessageBoxIcon.Information)
 End Sub

Offline

#2 2015-03-23 07:40:51

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: Keyboard Events

Could you tell me why you need to get key-up events?

Since most keys pressed inside worksheet will cause cell editing event, when the cell changed to Edit Mode, the cell key-up event will not be raised. Key down events (BeforeCellKeyDown and AfterCellKeyDown) should work.

So to get key-up event it is necessary to make the cell editing operation not be caused, there are several methods to disable cell editing, one of that is by handling BeforeCellEdit event:

Dim WSheet = grid.CurrentWorksheet
AddHandler WSheet.CellMouseMove, AddressOf Grid_CellMouseMove
AddHandler WSheet.BeforeCellEdit, AddressOf GSheet_BeforeCellEdit  ' <- Here
AddHandler WSheet.CellKeyUp, AddressOf GSheet_CellKeyUp

...

Private Sub GSheet_BeforeCellEdit(ByVal sender As Object, ByVal e As CellBeforeEditEventArgs)
  ' Disable cell edit
  e.IsCancelled = True
End Sub

225.png

Offline

#3 2015-03-23 12:02:13

James
Member
Registered: 2015-03-23
Posts: 5

Re: Keyboard Events

Thank-you Jing for your quick response.  Re. key-up events, it was the way I interpreted the documentation; your words "most keys pressed inside worksheet will cause cell editing event" are the relevant ones.  It now works though I found that  Me.StartPosition = ...  inactivated AddHandler Sheet.AfterCellKeyDown unless Me.StartPosition =  was placed at the end of the Load Sub.

Offline

Board footer

Powered by FluxBB