0

I'd like to make datagridview docked bottom. But when I press the key, nothing happens. Here's my code:

Private Sub MakbuzTDataGridView_KeyDown(sender As Object, e As KeyEventArgs)

    If e.KeyCode = Keys.F9 Then

        MakbuzTDataGridView.Dock = DockStyle.Bottom

        Me.Validate()
        Me.MakbuzTBindingSource.EndEdit()

    End If

End Sub

I'm using Visual Studio 2012

nikel
  • 653
  • 4
  • 13
  • 24

1 Answers1

2

Without actually checking your logic inside the sub, I can see right away that none of it is being called. You're missing the Handles clause at the end of your sub procedure.

Change the .KeyPreview property of the form to True.

Private Sub MakbuzTDataGridView_KeyDown(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress


        If e.KeyChar = ChrW(Windows.Forms.Keys.F9) Then
           MakbuzTDataGridView.Dock = DockStyle.Bottom
           Me.Validate()
           Me.MakbuzTBindingSource.EndEdit()
        End If
End If

End Sub

Also in the past when I've done this I've used KeyPressEventArgs instead of KeyEventArgs, but I'm not sure if there is a difference.

Brandon
  • 915
  • 4
  • 23
  • 44
  • Thanks for the answer. I tried it but it underlines "KeyPress" word. http://img580.imageshack.us/img580/8250/3mpr.png – nikel Oct 25 '13 at 12:12
  • Try Changing your KeyEventArgs to KeyPressEventArgs – Brandon Oct 25 '13 at 12:13
  • Same thing, nothing happens. – nikel Oct 25 '13 at 12:20
  • breakpoint the Sub, it should be getting called anytime you press a key? Then MakbuzTDataGridView.Dock = DockStyle.Bottom should be getting called when you hit f9 – Brandon Oct 25 '13 at 12:24
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/39999/discussion-between-brandon-j-and-nikel) – Brandon Oct 25 '13 at 12:40