Autocomplete text field for .net with separator support

I am developing an application that requires an autocomplete / sentence (drop down) text field for multiple words (separated by a separator as space), like a tag text field here in StackOverflow.

For example, I start typing โ€œapplicationโ€ and it should show all the words in the sentence list, starting with the application, and when I enter a word and a space and start typing a new word, it should show all sentences for this partial word.

Is there an example that I can take a look at?

+4
source share
1 answer

Hope this helps. I use developer tools, but the same thing can be used with 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 
+1
source

Source: https://habr.com/ru/post/1346846/


All Articles