Howdy, Stranger!

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

Categories

Datagrid query

smartshabsmartshab Member Posts: 4
Hello friends.. I am using vb.net. 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..

Comments

  • marius40marius40 Member Posts: 42
    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
    Form2.ShowDialog()
    End If
    End Sub[/code]
  • smartshabsmartshab Member Posts: 4
    Yes i tried ur code but its not working. plz help me with some other code. thnx in advance....
  • marius40marius40 Member Posts: 42
    Which version of VB are you using?
  • seancampbellseancampbell Pennsylvania, USAMember Posts: 684 ✭✭✭
    Marius,

    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.

    Smartshab,

    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".
    -Sean
  • smartshabsmartshab Member Posts: 4
    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.