提问人:siwa86 提问时间:9/26/2023 更新时间:9/26/2023 访问量:63
如何在 vb.net 中自动完成 TextBox 后调用 Keydown TextBox [已关闭]
How to call Keydown TextBox after AutoComplete TextBox in vb.net [closed]
问:
如何在 vb.net 中自动完成 TextBox 后调用 Keydown TextBox。
从“自动完成”文本框中进行选择后,我按以确保代码产品是否在数据库中,但是在我从“自动完成文本框”中选择适当的代码后,问题就出现了,然后按Enter键,然后出现所有消息框。我的代码有问题吗?
谢谢
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Using conn = New OleDbConnection(connectionString)
conn.Open()
resultList = conn.Query(Of Items)("SELECT * FROM Items").ToList()
TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
TextBox1.AutoCompleteCustomSource.AddRange(resultList.Select(Function(n) n.CODEPRODUCT).ToArray())
conn.Close()
End Using
End Sub
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
Using conn = New OleDbConnection(connectionString)
conn.Open()
resultList = conn.Query(Of Items)("SELECT CODEPRODUCT FROM Items WHERE '" + TextBox1.Text + "'").ToList()
conn.Close()
MsgBox("Not Found product code...")
Return
End Using
End If
End Sub
答: 暂无答案
评论
TextBox1_KeyDown
SelectedItem
Items
you only want to show a messagebox if the resulting list is empty
Why are you not using a ComboBox instead of a TextBox?
In that case, the SelectedItem is already an Items object, so you don't need to re-query