?
Solved

How do I catch the Enter key on a combo box?

Posted on 2004-09-08
5
Medium Priority
?
229 Views
Last Modified: 2010-04-23
Hi!

     Here's what I've got:  A crystal report on a form with 2 combo boxes above it.  One is for serial #, one is for stock #.  I want the user to be able to select the serial or stock from their lists OR to just type them in and press enter.  The report should then be updated.  Here's what I've got:

(cmbSerial and cmbStock are the combo box names)


  Private Sub cmbSerial_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        If e.KeyChar = Chr(13) Then
            CrystalReportViewer1.SelectionFormula = "{custody_audit.serial_no} = '" & cmbSerial.Text & "'"
            CrystalReportViewer1.RefreshReport()
            Debug.WriteLine("Serial Enter press")
            e.Handled = True
        End If
    End Sub


    Private Sub cmbStock_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        If e.KeyChar = Chr(13) Then
            CrystalReportViewer1.SelectionFormula = "{custody_audit.stock_number} = '" & cmbStock.Text & "'"
            CrystalReportViewer1.RefreshReport()
            Debug.WriteLine("Stock Enter press")
            e.Handled = True
        End If
    End Sub

This does almost nothing - the only thing I can tell is that when I click on the drop-down button for the serial combo box, I get the debug line "Serial Enter press" - doing the same for the stock number box does nothing.  Hitting enter in either does nothing.  

Thanks!

JP

0
Comment
Question by:gleznov
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 

Author Comment

by:gleznov
ID: 12015398
Here's another way I'm trying to do it:

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Const WM_KEYDOWN As Integer = &H100
        Const WM_SYSKEYDOWN As Integer = &H104
        Dim e As System.EventArgs
        Dim stk As Integer = 0
        Dim srl As Integer = 0

        If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
            Select Case (keyData)
                Case Keys.Enter
                    If cmbStock.Focus = True Then stk = 1
                    If cmbSerial.Focus = True Then srl = 1
                    Debug.WriteLine("Start of override:")
                    Debug.WriteLine("stk = " & stk & " & srl = " & srl)
                    stk = 0
                    srl = 0

                    '--------Do something here----------
                    If cmbStock.Focus = True Then
                        CrystalReportViewer1.SelectionFormula = "{custody_audit.stock_number} = '" & cmbStock.Text & "'"
                        CrystalReportViewer1.RefreshReport()
                        Debug.WriteLine("Stock Enter press")
                    Else
                        If cmbSerial.Focus = True Then
                            CrystalReportViewer1.SelectionFormula = "{custody_audit.serial_no} = '" & cmbSerial.Text & "'"
                            CrystalReportViewer1.RefreshReport()
                            Debug.WriteLine("Serial Enter press")
                        End If
                    End If
            End Select
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function


The problem here is that the debug.writelines show me that both combo boxes are in focus and whenever I hit enter, the field shifts from Serial to Stock.  if Stock is focused, it does not however switch back to serial.  cmbStock works, cmbSerial doesn't.  Why?

JP
0
 

Author Comment

by:gleznov
ID: 12015422
And I lied, stock box isn't working anymore either.

JP
0
 

Author Comment

by:gleznov
ID: 12015910
OK, I found a solution.  In case anyone's ever looking for something like this, let me post it:


 Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean

        If Me.ActiveControl.Name = "cmbSerial" And keyData = Keys.Enter Then

            'the control is the button and the user has pressed Enter key, so handle this.
            SerialUpdate()
            Return False
        ElseIf Me.ActiveControl.Name = "cmbStock" And keyData = Keys.Enter Then

            StockUpdate()
            Return False

        Else

            'Otherwise, let the key be processed normally.
            Return MyBase.ProcessDialogKey(keyData)

        End If

    End Function

    Private Sub SerialUpdate()
        CrystalReportViewer1.SelectionFormula = "{custody_audit.serial_no} = '" & cmbSerial.Text & "'"
        CrystalReportViewer1.RefreshReport()
        cmbStock.Text = ""
    End Sub

    Private Sub StockUpdate()
        CrystalReportViewer1.SelectionFormula = "{custody_audit.stock_number} = '" & cmbStock.Text & "'"
        CrystalReportViewer1.RefreshReport()
        cmbSerial.Text = ""
    End Sub
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12231815
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question