问题描述
大家好
我是VB.net的绝对首发
我试图将数据输入组合框并想要按下返回后触发一个子例程。
我试过这个:
Private Sub ComboBox1_TextChanged(发送者为对象,e为EventArgs)处理ComboBox1.TextChanged
,但这会在键入的第一个字母上触发。
ie如果我想输入John Doe,则只要我输入J,子程序就会启动
任何人都可以指出我正确的方向。
感谢提前给予
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
推荐答案
Combobox1_KeyDown
活动。
这里有一些代码可以开始:
event.
Here's some code to start:
If e.KeyCode = Keys.Enter Then
'call your sub here
End If
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
但我得到的代码错误是KeyCode不是'系统的成员。 EventArgs'对e.KeyCode
你能帮忙吗?
谢谢
PS只需将争论从e as EventArgs设置为e as KeyEventsArgs错误清除。
非常感谢你们您的支持解决方案运作良好。
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.
这篇关于如何通过在组合框中输入文本来触发子例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!