为分隔符支持.NET自动完成文本框 [英] autocomplete text box for .net with support for delimiter
问题描述
我在开发的要求与自动完成/建议一个文本框的应用程序(下拉)多个单词,如标签文本框在计算器这里(由状空间分隔符分隔)。
I am developing an application which requires a text box with auto-complete/suggestions (drop down) for multiple words (separated by a delimiter like space) like the tags text box here in StackOverflow.
例如,我开始打字应用,它应该显示在建议的所有单词列表开始的应用的,当我输入一个单词和preSS空间,并开始键入新字应显示该部分单词的所有建议。
For example, I start typing 'app' and it should show all words in the suggestions list starting with app, and when I enter a word and press space and start typing a new word it should show all suggestions for that partial word.
有一个例子,我可以看看?
Is there an example I can have a look at?
推荐答案
我希望这有助于..我使用的开发-EX preSS工具,但同样可以与普通的.NET组件使用。
I Hope this helps.. I'm using developer-express tools, but the same can be used with the regular .net components.
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
这篇关于为分隔符支持.NET自动完成文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!