|
-
Oct 25th, 2013, 03:34 PM
#1
Thread Starter
Addicted Member
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
-
Oct 25th, 2013, 04:33 PM
#2
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.
-
Oct 25th, 2013, 05:11 PM
#3
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.
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Oct 25th, 2013, 05:30 PM
#4
Re: Docking datagridview bottom
 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.
-
Oct 26th, 2013, 03:55 AM
#5
Thread Starter
Addicted Member
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.
-
Oct 26th, 2013, 04:17 AM
#6
Thread Starter
Addicted Member
Re: Docking datagridview bottom
KeyDown event solved the problem. Thank you all.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|