OnKeyDown event arise twice !

Jan 25, 2012 at 2:36 PM
Edited Jan 25, 2012 at 2:38 PM

Hi to everybody,

this is my first post... Excellent SourceGrid. I'm using it in a large project.

Everything goes right but when I try to intercept Enter Key I notice the OnKeyDown event arise twice...

How can I do to correctly show the messagebox only once?

My code is:

                        grid1(r, c) = New SourceGrid.Cells.Cell()
                        grid1(r, c).Value = "something..."

                    'associa alle celle voto il controller per la tastiera
                    grid1(r, c).AddController(New controllerTasti())

and the Controller class is:

Public Class controllerTasti : Inherits SourceGrid.Cells.Controllers.ControllerBase

    ' controller per gestione input tastiera sulle celle voto della grid
    '

    Public Overrides Sub OnKeyDown(ByVal sender As SourceGrid.CellContext, ByVal e As System.Windows.Forms.KeyEventArgs)
        MyBase.OnKeyDown(sender, e)

        If e.KeyCode <> Keys.Enter Then Exit Sub

        MessageBox.Show("enter")     '<- TWICE !?!

    End Sub

    Public Overrides Sub OnKeyPress(ByVal sender As SourceGrid.CellContext, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        :
        :
    End Sub
End Class

 

Thanks a lot,

Andrea.

Jan 25, 2012 at 3:49 PM

Resolved:


    Public Overrides Sub OnKeyDown(ByVal sender As SourceGrid.CellContext, ByVal e As System.Windows.Forms.KeyEventArgs)
        MyBase.OnKeyDown(sender, e)

        If e.KeyCode <> Keys.Enter Then Exit Sub

        If e.Handled Then Exit Sub

        MessageBox.Show("enter ONCE :-)")
        e.Handled = True

    End Sub

hope this will be helpful for someone else.

Andrea.