[Resolved] Adding item to listbox with Enter Keypress
I have been out of VB since VB 6, but am back into it to write a basic app. I have created a listbox and am able to add data to it from a textbox via a command button. However, I want to give the user the option to simply press the enter key after they have entered the info the textbox, instead of clicking on the command button. I tried calling the function the command button is using from the "ENTER" event on the textbox, but all that does is execute the function when I click on the textbox? I'm sure this is very simple. What am I missing? Thanks for any help.
Re: Adding item to listbox with Enter Keypress
Hey,
On the KeyPress Event, when you find the user has pressed the enter button put the following code:
Code:
Button1.PerformClick()
(where Button1 is the name of your command button).
This will have the same effect as if the user clicked the button.
Gary
Re: Adding item to listbox with Enter Keypress
When you say "am back into it" do that mean you are still using VB6.0? If yes then you have posted in the wrong section.
If it would have been VB6.0 then what you want can be done like this.
Code:
Option Explicit
Private Sub Command1_Click()
MsgBox "Called!"
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyPress = 13 Then ' enter key was pressed
KeyPress = 0 'suppress sound
Command1_Click 'call the Command1 click procedure
End If
End Sub
Re: Adding item to listbox with Enter Keypress
Nope, I have previous experience with VB6, but just started programming again and am now using VB.NET 2008 Express.
Re: Adding item to listbox with Enter Keypress
Another method is you can specify in your form's property AcceptButton the button which you like to be triggered when you press Enter key.
Its like setting the Default property to True of a command button in VB6.0.
Re: Adding item to listbox with Enter Keypress
Quote:
Originally Posted by dee-u
Another method is you can specify in your form's property AcceptButton the button which you like to be triggered when you press Enter key.
Its like setting the Default property to True of a command button in VB6.0.
Good thinking!! :)