VB.Net文本框自动完成所选项目

时间:2011-01-27 15:37:31

标签: vb.net autocomplete

我有一个vb.net表单,上面有一个文本框,设置为从数据库中自动完成自定义集合。当用户从自动完成列表中找到所需的值时,是否会触发事件?

2 个答案:

答案 0 :(得分:7)

当用户按下列表中项目的Enter或Double Clicks时,Key.WownCode = 13会触发KeyDown事件。

答案 1 :(得分:0)

* 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