开发者

VB.Net Textbox Autocomplete Selected Item

I have a vb.net form with a textbox on it set to autocomplete custom collection from a database. Is there an event that fires when a user finds the value they w开发者_StackOverflow社区ant from the autocomplete list?


The KeyDown event fires with e.KeyCode = 13 when the user presses Enter or Double Clicks on an item in the list.


Try this Aucomplete for Textbox in *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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜