Results 1 to 10 of 10

Thread: [RESOLVED] Loosing key press after function key

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    350

    Resolved [RESOLVED] Loosing key press after function key

    I have a dialog box and am entering the 'date', 'job number', 'code' etc. and am using function keys to speed up the entry.

    I am using the following code to get the key press on the date text field.
    If Enter is pressed move to the next field.
    If F9 is pressed copy the date from the datagridview and move to the job number field.
    If F10 is pressed copy the next date from the datagridview and move to the job number field.
    If F11 is pressed copy the date and job no from the datagridview and move to the code field.
    If F12 is pressed copy the next date date and job no from the datagridview and move to the code field.

    When F9 or F10 is pressed and it moves to the job number field, the first character I enter is lost, i.e.if I enter "123", I just get "23".
    Any idea why that is occurring.
    I don't get the problem on the code field.

    Code:
        Private Sub txtDate_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtDate.KeyDown
            Dim MyDate As Date
            Dim str As String
    
            Select e.KeyCode
    
                Case Keys.Enter ' press Return - move to next field
                    Me.SelectNextControl(DirectCast(sender, Control), True, True, True, True)
                    e.SuppressKeyPress = True
    
                Case Keys.F9 ' same date
                    If lblFunction9.Visible Then
                        str = frmEditTimesheet.GridTimesheet(ColDate, frmEditTimesheet.GridTimesheet.RowCount - 1).Value
                        txtDate.Text = frmEditTimesheet.GridTimesheet(ColDate, frmEditTimesheet.GridTimesheet.RowCount - 1).Value
                        txtJobNo.Focus()
                    End If
    
                Case Keys.F10 ' next date
                    If lblFunction10.Visible Then
                        MyDate = frmEditTimesheet.GridTimesheet(ColDate, frmEditTimesheet.GridTimesheet.RowCount - 1).Value
                        txtDate.Text = MyDate.AddDays(1)
                        txtJobNo.Focus()
                    End If
                Case Keys.F11 ' same date & job
                    If lblFunction11.Visible Then
                        txtDate.Text = frmEditTimesheet.GridTimesheet(ColDate, frmEditTimesheet.GridTimesheet.RowCount - 1).Value
                        txtJobNo.Text = frmEditTimesheet.GridTimesheet(ColJobNo, frmEditTimesheet.GridTimesheet.RowCount - 1).Value
                        txtCode.Focus()
                    End If
                Case Keys.F12 ' next date & job
                    If lblFunction12.Visible Then
                        MyDate = frmEditTimesheet.GridTimesheet(ColDate, frmEditTimesheet.GridTimesheet.RowCount - 1).Value
                        txtDate.Text = MyDate.AddDays(1)
                        txtJobNo.Text = frmEditTimesheet.GridTimesheet(ColJobNo, frmEditTimesheet.GridTimesheet.RowCount - 1).Value
                        txtCode.Focus()
                    End If
            End Select
        End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Loosing key press after function key

    This is a bit of a hunch but what happens if you use the KeyUp event instead of KeyDown? Also, given that the documentation explicitly states that you should use Select rather than Focus, you should probably use Select rather than Focus.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    350

    Re: Loosing key press after function key

    Thanks,
    I have just noticed it only happens with F10.
    I have tried changing to Keyup & using Select but it has had no effect.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    350

    Re: Loosing key press after function key

    Quote Originally Posted by DavidGraham167 View Post
    Thanks,
    I have just noticed it only happens with F10.
    I have tried changing to Keyup & using Select but it has had no effect.
    Also I get a beep when I press the character that is lost after pressing F10.
    I.e. if I press "123" I get beep "23".

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Loosing key press after function key

    Just for fun I had it selet the Job textbox before setting it and moving on to the next one...
    I also cleaned up the code some and simplified thigns down...

    Code:
        Private Sub txtDate_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtDate.KeyDown
            Dim MyDate As Date = frmEditTimesheet.GridTimesheet(ColDate, frmEditTimesheet.GridTimesheet.RowCount - 1).Value
            Dim MyJob As String = frmEditTimesheet.GridTimesheet(ColJobNo, frmEditTimesheet.GridTimesheet.RowCount - 1).Value
    
            Select e.KeyCode
    
                Case Keys.Enter ' press Return - move to next field
                    Me.SelectNextControl(DirectCast(sender, Control), True, True, True, True)
                    e.SuppressKeyPress = True
    
                Case Keys.F9 ' same date
                    If lblFunction9.Visible Then
                        txtDate.Text = MyDate
                        txtJobNo.Select()
                    End If
    
                Case Keys.F10 ' next date
                    If lblFunction10.Visible Then
                        txtDate.Text = MyDate.AddDays(1)
                        txtJobNo.Select()
                    End If
                Case Keys.F11 ' same date & job
                    If lblFunction11.Visible Then
                        txtDate.Text = MyDate
                        txtJobNo.Text = MyJob
                        txtCode.Select()
                    End If
                Case Keys.F12 ' next date & job
                    If lblFunction12.Visible Then
                        txtDate.Text = MyDate.AddDays(1)
    					txtJobNo.Select()
                        txtJobNo.Text = MyJob
                        txtCode.Select()
                    End If
            End Select
        End Sub
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    350

    Re: Loosing key press after function key

    Quote Originally Posted by techgnome View Post
    Just for fun I had it selet the Job textbox before setting it and moving on to the next one...
    I also cleaned up the code some and simplified thigns down...
    -tg
    Thanks, I tried that but I still have the same problem.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    350

    Re: Loosing key press after function key

    I changed

    Case Keys.F10 ' next date

    to

    Case Keys.F8 ' next date

    and it worked - but I don't know why.

  8. #8
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Loosing key press after function key

    Likely you have another application running that is monitoring your F10 key. It could even be the keyboard itself has a kinda iTouch mode that my logitech does, that when activated will run commands.

  9. #9
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: Loosing key press after function key

    F10 is a Windows system key (normally activates the menu bar options for the current window). You can solve your problem by adding an e.SuppressKeyPress = True to your KeyDown event handler.
    Code:
    Case Keys.F10 ' next date
        If lblFunction10.Visible Then
            txtDate.Text = MyDate.AddDays(1)
            txtJobNo.Select()
    
            e.SuppressKeyPress = True
    
        End If

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    350

    Re: Loosing key press after function key

    Thanks, that's it solved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width