Docking datagridview bottom
I have a datagrid on my form. It docks fill when I click a button. Then when I press F9 it should dock bottom but nothing happens. Here's my code:
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
Re: Docking datagridview bottom
Move the code to the Form's keydown event and set the form's KeyPreview property to True and see if that works. Right now you have the code in the DataGridView's keydown event which means that the DataGridView has to be focused but you can't have a cell focused.
Re: Docking datagridview bottom
The problem is a bit deeper than that, your Sub, even though it is named MakbuzTDataGridView_KeyDown, it actually does not have an event handler. So nothing is calling it ever, not even if you are inside the DataGridView.
Re: Docking datagridview bottom
Quote:
Originally Posted by
kaliman79912
it actually does not have an event handler
Ahh, good catch. I didn't see that.
@Op - The event handler not being with the Sub is common when you copy and paste events. Just be sure that if you are copying and pasting events that it keeps the handler.
Re: Docking datagridview bottom
Thanks for the replies. I tried this:
Code:
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
And set the keypreview to true (not programmatically). Same thing, nothing happens.
Re: Docking datagridview bottom
KeyDown event solved the problem. Thank you all.