我正在使用下面的代码在我的数据库中进行搜索,但我的按键表现得很奇怪。
Private Sub txtSearch4_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtSearch4.KeyPress
Call btnSearch4_Click(sender, e)
End Sub
Private Sub btnSearch4_Click(sender As Object, e As EventArgs) Handles btnSearch4.Click
If SQL.HasConnection = True Then
SQL.ExecQuery("SELECT Customer, Product, Part_Number FROM Product WHERE (" & cmbType4.Text & " LIKE '%" & txtSearch4.Text & "%') ORDER BY Part_Number ASC")
If SQL.DBDS.Tables.Count > 0 Then
dgvProd.DataSource = SQL.DBDS.Tables(0)
End If
End If
End Sub
视频:https://drive.google.com/open?id=0B7BUg5POgN7dZGVBTUpad1FWdDg 正如您在视频中看到的,当我按下一个键时,它不会立即启动。我想这样,当我按下一个键时,它会像按下按钮一样自动开启。 谢谢你们。
答案 0 :(得分:1)
请改用KeyDown事件。一旦按下键盘上的键,就会引发此事件,而当按下键并由用户释放键时,会针对字符键引发KeyPress事件。
Private Sub txtSearch4_KeyDown(sender As Object, e As KeyPressEventArgs) Handles txtSearch4.KeyDown doSearch() End Sub Private Sub btnSearch4_Click(sender As Object, e As EventArgs) Handles btnSearch4.Click doSearch() End Sub Private Sub doSearch() If SQL.HasConnection = True Then SQL.ExecQuery("SELECT Customer, Product, Part_Number FROM Product WHERE (" & cmbType4.Text & " LIKE '%" & txtSearch4.Text & "%') ORDER BY Part_Number ASC") If SQL.DBDS.Tables.Count > 0 Then dgvProd.DataSource = SQL.DBDS.Tables(0) End If End If end sub