F9 and Keydown event in vb.net

Hi

This is very urgent.  I have keydown event at form level.  I load the form, do search after getting results into the grid, I select the row and press F9 it should take some info from the grid and put it in other form's textbox.  This happens first time and second time I do the search and getting the results the results into the grid do the F9 doesn't give me the results.  WHy is that?  I also set the forms keypreview to true.  My code as follows:

If keycode = 120 then
take the info from the grids row and put it in another form
end if
RoshiniAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

planoczCommented:
sample code....
You can use this to catch whatever key that is pressed....
Just change the code to fit your needs.

  Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
        Const WM_KEYDOWN As Integer = &H100
        Const WM_SYSKEYDOWN As Integer = &H104

        If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
            Select Case (keyData)
                Case Keys.Right
                    Me.Parent.Text = "Right Arrow Captured"
                Case Keys.Left
                    Me.Parent.Text = "Left Arrow Captured"
                Case Keys.Down
                    Me.Parent.Text = "Down Arrow Captured"
                Case Keys.Up
                    Me.Parent.Text = "Up Arrow Captured"
                Case Keys.Tab
                    Me.Parent.Text = "Tab Key Captured"
                Case (Keys.Control Or Keys.M)
                    Me.Parent.Text = "<CTRL> + M Captured"
                Case (Keys.Alt Or Keys.Z)
                    Me.Parent.Text = "<ALT> + Z Captured"
            End Select
        End If

        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
0
RoshiniAuthor Commented:
See my code below.

if keycode = 120 (for f9) then
system.windows.forms.sendkeys.sendwait("{END}")
system.windows.forms.sendkeys.sendwait(" ")
system.windows.forms.sendkeys.sendwait(Whatever I have data in grid's row)

0
planoczCommented:
Do you want data from all datagrid rows or just the one that you selected?
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

RoshiniAuthor Commented:
I just wanted data from the row(actually rowsel (used component one flex grid)) I selected from the grid.  In the grid I have two columns code and description.  
0
planoczCommented:
Global Var to pass to the next form

   Public  sQty As String
   Public  sDescription As String
   Public  sCost As String
   Public  sOnHand As String

  Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
        Const WM_KEYDOWN As Integer = &H100
        Const WM_SYSKEYDOWN As Integer = &H104

        Try
            If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
                Select Case (keyData)
                    Case Keys.F9
                        sQty = Datagrid1.Item(Datagrid1.CurrentRowIndex, 1)                 '<--- columns 1
                        sDescription = Datagrid1.Item(Datagrid1.CurrentRowIndex, 2)      '<--- columns 2
                        sCost = Datagrid1.Item(Datagrid1.CurrentRowIndex, 3)                '<--- columns 3
                        sOnHand = Datagrid1.Item(Datagrid1.CurrentRowIndex, 4)           '<--- columns 4
                End Select
            End If
        Catch ex As InvalidCastException
            'Skip DBNULL
        Catch ex As SystemException
            MsgBox(ex.StackTrace & ex.Message, MsgBoxStyle.Critical, "General Error")
        End Try
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
0
planoczCommented:
This code as for  the Micro$oft datagrid control I do not have the flex grid.
0
gregasmCommented:
And this PAQ:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20715177.html

This presents another method, in case you don't want to resort to hacking using ProcessCmdKey ;]

This one relates to the regular .net datagrid, but as usual, requires custom controls programming.
0
RoshiniAuthor Commented:
Let me explain it again.  I have a form with label, textbox, command button and grid(flex grid).  As soon as I load the form I put search string on to the textbox and press command button, it brings data onto the grid.  In the grid I have two columns code and description.  I select the row to select the code and press F9 it will pass the row's code info to other form.  It works first time and second time I will do different search string info onto the grid and select the rows code info and press F9 it doesn't work.  It goes to first row of the grid and takes the info from the grid row and paste it there.  I think its not catching grid's keypress event.  I have following code in grids keypress event.

If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
            e.Handled = True
            GetSymData((SymRecGrid.Item(SymRecGrid.RowSel, 0)))
End If

So how can I catch grids keypress event?  So please help me experts.
0
gregasmCommented:
to catch the grid's keypress event, you must catch the gridcelltextbox's keypress event.

please refer to this paq
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20715177.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RoshiniAuthor Commented:
But how come it works first time without catching gridcelltextbox's keypress event.  I am using component one flex grid for .net in my project.  It doesn't have gridcelltextbox.  You can directly go into the grid and edit.  Still I couldn't figure it out where its going wrong.  
0
planoczCommented:
The problem is that you are using a 3rd party control.
So you will have to find the code from that side and not the .net side.
You may have to get ahold of the software Manufacture the find the right method and property to use.
0
gregasmCommented:
It works the first time because the grid has the focus. The second time, the gridcelltextbox has the focus. It's not that obvious, but that is what I believe is the case. It was like that for me when I encountered this scenario.
0
gregasmCommented:
I had this same question in the past, and I referred him to the same question I asked, that helped me solve this problem.
0
RoshiniAuthor Commented:
Nobody I answered my question and I was out of that project no need to get the answer.  So please delete the question.  Thanks.
0
gregasmCommented:
it sounds like you did not understand the answer that was provided. But it doesn't matter to me.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.