我正在开发一个应用程序,它需要一个带有自动完成/建议(下拉)的文本框,用于多个单词(由空格分隔符分隔),就像StackOverflow中的标签文本框一样. 例如,我开始输入“app”,它应该以app开头显
例如,我开始输入“app”,它应该以app开头显示建议列表中的所有单词,当我输入单词并按空格键并开始输入新单词时,它应显示该部分单词的所有建议.
有一个例子我可以看看吗?
我希望这有帮助..我使用的是开发人员快速工具,但同样可以与常规.net组件一起使用.Private Sub txtToEmail_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtToEmail.EditValueChanged Try Dim Emails As New List(Of String) Emails.Add("123@abc.com") Emails.Add("456@dfg.com") Emails.Add("abc@123.com") Emails.Add("dfg@456.com") Dim Txt = Trim(CStr(txtToEmail.EditValue)) Dim Suggestions As IEnumerable(Of String) If Txt <> "" Then If Txt.IndexOf(",") = -1 Then Suggestions = From c In Emails Where c.StartsWith(Txt) Select c Else Dim lastIndex = Txt.LastIndexOf(",") Dim lastWord = Trim(Txt.Substring(lastIndex + 1)) Suggestions = From c In Emails Where c.StartsWith(lastWord) Select c End If EmailList.Items.Clear() For Each r In Suggestions EmailList.Items.Add(r) Next End If If EmailList.ItemCount > 0 Then EmailList.Visible = True End If Catch ex As Exception ShowErrorBox(ex) End Try End Sub Private Sub EmailList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmailList.Click Try If EmailList.SelectedValue = Nothing OrElse EmailList.SelectedValue = "" Then Return Dim Txt = CStr(txtToEmail.EditValue) If Txt.IndexOf(",") = -1 Then txtToEmail.EditValue = EmailList.SelectedValue Else Dim lastIndex = Txt.LastIndexOf(",") txtToEmail.EditValue = Txt.Substring(0, lastIndex + 1) & EmailList.SelectedValue End If txtToEmail.Focus() txtToEmail.SelectionStart = CStr(txtToEmail.EditValue).Length EmailList.Visible = False Catch ex As Exception ShowErrorBox(ex) End Try End Sub