-1

I need to pass the text data in a particular column in my grid to a textbox when enter key is pressed. I am unable to do so since the key down event is just not getting fired.

    if e.keycode = keys.enter Then

    "My Code Here"

    End If

What do i do so that my grid responds to the Key Down Event? P.S. - KeyPreveiew property of my form is set to true

user1508599
  • 21
  • 1
  • 7
  • Unclear. What KeyDown event? The one for the Form or the one for the Grid? If KeyPreview is true then you get the KeyDown on the form. – Steve Dec 26 '17 at 08:51
  • Key Down for the grid. Mentioned about the KeyPreview property since i saw in many places that KeyPreview Property on any form needs to be set true for any of its control to respond to certain events – user1508599 Dec 26 '17 at 09:05
  • If you set the KeyPreview=True than you should add a KeyDown event handler for the Form not for the Grid. When KeyPreview is true the Form intercepts the event and it never reaches the Grid. If you set KeyPreview=False then the Grid will see the KeyDown event – Steve Dec 26 '17 at 09:19
  • just changed the KeyPreview property of the form to "False". It still does not seem to work. Its really frustrating. Been trying to find out a solution to this since 2 days – user1508599 Dec 26 '17 at 09:27
  • Possible duplicate of [DataGridView keydown event not working in C#](https://stackoverflow.com/questions/4284370/datagridview-keydown-event-not-working-in-c-sharp) – Visual Vincent Dec 26 '17 at 10:56

1 Answers1

0

Could it be your formating?

If e.KeyCode = Keys.Enter Then
   "my code" 
end if

Have you tried declaring?

Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As UShort

if GetAsyncKeyState(key number) then
    "my code" 
    EndIf
Scott Chambers
  • 581
  • 6
  • 22
  • its not the problem of the code. Whatever code I write in there will be in my KeyDownEvent of my grid. SInce it aint getting fired, the compiler does not reach the code at all. My Grid is not firing the KeyDownEvent – user1508599 Dec 26 '17 at 09:31
  • FYI VB.NET is case-insensitive, so for example `e.keycode` and `e.KeyCode` counts as the same thing for the compiler. – Visual Vincent Dec 26 '17 at 10:53
  • @VisualVincent good to know. not a big vb.net coder, just thought id help if i could. Sorry. – Scott Chambers Dec 26 '17 at 12:01
  • You don't have to apologise for trying to help. A lot of programming languages are case-sensitive so assuming that VB.NET is as well is an easy (and harmless) mistake to make. It proves that you are human. ;) – Visual Vincent Dec 26 '17 at 12:37