我读过的每条评论都说这段代码有效...... 但是当我尝试在文本框中键入文本时,没有自动填充功能出现,它只是闪烁..请帮忙,我是winforms的新手
Private Sub txsCusID_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txsCusID.TextChanged
Dim cmd As New SqlClient.SqlCommand("SELECT DISTINCT fname + ' ' + lname AS clist FROM tblclient WHERE id LIKE '%" + txsCusID.Text.ToString + "%'", sqlconstr)
Dim ds As New DataSet
Dim da As New SqlClient.SqlDataAdapter(cmd)
da.Fill(ds, "list")
Dim col As New AutoCompleteStringCollection
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)("clist").ToString())
Next
txsCusID.AutoCompleteSource = AutoCompleteSource.CustomSource
txsCusID.AutoCompleteCustomSource = col
txsCusID.AutoCompleteMode = AutoCompleteMode.Suggest
End Sub
答案 0 :(得分:0)
这里尝试一下......我建议你设置你的桌子,然后在添加到源代码时循环播放......
Dim dtCustomerNames As DataTable
dtCustomerNames = ds.Tables(0)
For Each row As DataRow In dtCustomerNames.Rows
'You have to continue to add your data here...'
txsCusID.AutoCompleteCustomSource.Add((row.Item("clist").ToString))
Next
txsCusID.AutoCompleteMode = AutoCompleteMode.Suggest
txsCusID.AutoCompleteSource = AutoCompleteSource.CustomSource
让我知道它是如何为你工作的......
谢谢!