2011-01-27 41 views

回答

5

當用戶按下Enter或雙擊列表中的項目時,KeyDown事件觸發e.KeyCode = 13。

+0

簡單的解決方案,謝謝! – 2017-05-30 06:58:29

1

試試這個Aucomplete爲文本框在 * vb.net *

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