我已经为自动完成创建了一个代码,但不知道它为什么不起作用。
Private Sub btnrefresh_Click(sender As Object, e As EventArgs) Handles btnrefresh.Click
txtledgersearch.AutoCompleteMode = AutoCompleteMode.Suggest
txtledgersearch.AutoCompleteSource = AutoCompleteSource.CustomSource
Dim DataCollection As New AutoCompleteStringCollection()
getData(DataCollection)
txtledgersearch.AutoCompleteCustomSource = DataCollection
End Sub
Private Sub getData(ByVal dataCollection As AutoCompleteStringCollection)
On Error Resume Next
Dim adapter As New OleDbDataAdapter
con = New OleDbConnection(connectionString)
con.Open()
Dim dt As New DataTable
Dim ds As New DataSet
sqlstr = "SELECT LedgerTab.lname FROM LedgerTab;"
ds.Tables.Add(dt)
adapter.SelectCommand = New OleDbCommand(sqlstr, con)
For Each row As DataRow In ds.Tables(0).Rows
dataCollection.Add(row(0).ToString())
Next
End Sub
我没理解为什么我的代码无效。
答案 0 :(得分:0)
检查数据是否从DB填充到dataCollection。 尝试移动此scode snipet以加载事件
txtledgersearch.AutoCompleteMode = AutoCompleteMode.Suggest
txtledgersearch.AutoCompleteSource = AutoCompleteSource.CustomSource
Dim DataCollection As New AutoCompleteStringCollection()
getData(DataCollection)
txtledgersearch.AutoCompleteCustomSource = DataCollection