我在组合框中有自动完成功能,它工作正常但没有什么问题,我建议文本长度超过3个字符的建议列表,但列表出现在4个字符长度后(当用户输入文本的第五个字符)这意味着当第一次执行代码时,列表没有出现在Text_Changed
事件
Private Sub TxtItem_TextChanged(sender As System.Object, e As System.EventArgs) Handles TxtItem.TextChanged
If Trim(TxtItem.Text) <> "" And Trim(TxtItem.Text).Length > 3 Then
'Autocomplete
Dim Bl As New ItemBL
Dim suggestions = Bl.DisplayLikeNameList(Trim(TxtItem.Text))
Dim MySource As New AutoCompleteStringCollection()
MySource.AddRange(suggestions.ToArray)
With TxtItem
.AutoCompleteMode = AutoCompleteMode.Suggest
.AutoCompleteSource = AutoCompleteSource.CustomSource
.AutoCompleteCustomSource = MySource
End With
TxtItem.Select(TxtItem.Text.Length, 0)
Exit Sub
Else
TxtItem.AutoCompleteMode = AutoCompleteMode.None
End If
End Sub
注意:此问题会导致应用程序在Windows XP上退出(有时),但不会影响Windows 7
答案 0 :(得分:0)
答案在这篇文章中找到:Dynamically changing Textbox's AutoComplete List causes AccessViolationException, any advice?
所以我必须制作全局建议列表并在表单AutoComplete
事件中初始化load
属性并且它运行良好。