Datagrid query

Hello friends.. I am using i am having datagrid on my form. Now i want that when i enter datagrid and i press insert key from keyboard, new form should get open. plz help..


  • Try this

    [code] Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
    If e.KeyCode = Keys.Insert Then
    End If
    End Sub[/code]
  • Yes i tried ur code but its not working. plz help me with some other code. thnx in advance....
  • Which version of VB are you using?
  • seancampbellseancampbell Pennsylvania, USA

    The code you provided should work in all frameworks.

    The only time a KeyPressed, KeyDown, or KeyUp event is handled, is when the object itself has Focus of the user input. For instance, if you set TextBox1_KeyPressed method to handle the Insert press, and you did have your cursor focus in that TextBox, it wouldn't handle any keyboard presses.

    That said, accepting keyboard commands gets pretty tricky when you have many elements on a form that can have focus.


    Try this: Add that same function to Form1_KeyPress event and see if it works for you.

    Maybe there is a better way to do what you want. Check out "context menus".
  • Thnx for ur reply. i am using vb.net2008. i have tries the same code in Form1_Keydown event, its working fine. but only datagrid1_keydown its not working.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!