当用户从自动完成中选择任何项目时,VB.NET 中是否会触发任何事件TextBox
?
下面是我的代码:
Private Sub txtFilterBy_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtFilterBy.TextChanged
txtSearch("Select Name From items", txtFilterBy)
End Sub
Public Sub txtSearch(ByVal strsql As String, ByVal textboxName As TextBox)
con.ConnectionString = constr
Excercise_Add.con.Open()
Dim namesCollection As New AutoCompleteStringCollection()
cmd = New MySqlCommand(strsql,con)
da.SelectCommand = cmd
read = cmd.ExecuteReader()
While (read.Read)
namesCollection.Add(read(0).ToString())
End While
textboxName.AutoCompleteMode = AutoCompleteMode.Suggest
textboxName.AutoCompleteCustomSource = namesCollection
textboxName.AutoCompleteSource = AutoCompleteSource.CustomSource
con.Close()
End Sub