Results 1 to 6 of 6

Thread: Docking datagridview bottom

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    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

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    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.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    Re: Docking datagridview bottom

    Quote Originally Posted by kaliman79912 View Post
    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.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    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
  •  



Click Here to Expand Forum to Full Width