• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 954
  • Last Modified:

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
0
Roshini
Asked:
Roshini
  • 6
  • 5
  • 5
1 Solution
 
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
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
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
 
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

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 6
  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now