Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All
I am an absolute starter in VB.net

I am trying to enter data into a combo box and want to trigger a sub routine once I press return.
I tried this:
Private Sub ComboBox1_TextChanged(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged
but this triggers on the first letter typed.
ie If I want to enter "John Doe" the sub routine starts as soon as I enter the "J"
Can anyone point me in the right direction.

Thanks given in advance
Posted

Use the
Combobox1_KeyDown
event.

Here's some code to start:

VB
If e.KeyCode = Keys.Enter Then
          'call your sub here
      End If
 
Share this answer
 
chrisf8657

Thank you for your suggestion. I have modified my code as follows;

VB
Private Sub Player1_KeyDown(sender As Object, e As EventArgs) Handles Player1.KeyDown
        'set curComboItem to the text contained within the ComboBox
        Dim curComboItem = Player1.Text.ToString()
        'set curCombo to name of combobox
        Dim curCombo = Player1
        'check to see if last keystroke was the enter key if so run sub routine
        If e.KeyCode = Keys.Enter Then
            ComboBox_Update(curComboItem, curCombo)
        End If
    End Sub




but I get a code error of "KeyCode is not a member of 'System.EventArgs' against e.KeyCode

Can you help?

Thanks

PS Just set the arguement from "e as EventArgs" to "e as KeyEventsArgs" error cleared.

Thank you very much for your support the solution works well.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900