VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Datagrid query Posted by smartshab on 13 Jul 2010 at 11:29 PM
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..
Report
Re: Datagrid query Posted by marius40 on 15 Jul 2010 at 5:26 AM
Try this

 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

Report
Re: Datagrid query Posted by smartshab on 15 Jul 2010 at 11:10 AM
Yes i tried ur code but its not working. plz help me with some other code. thnx in advance....
Report
Re: Datagrid query Posted by marius40 on 15 Jul 2010 at 11:38 AM
Which version of VB are you using?
Report
Re: Datagrid query Posted by seancampbell on 15 Jul 2010 at 2:03 PM
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
Report
Re: Datagrid query Posted by smartshab on 16 Jul 2010 at 10:54 PM
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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.