Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Datagrid query

smartshabsmartshab Posts: 4Member
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 Posts: 42Member
    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 Posts: 4Member
    Yes i tried ur code but its not working. plz help me with some other code. thnx in advance....
  • marius40marius40 Posts: 42Member
    Which version of VB are you using?
  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    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 Posts: 4Member
    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.