# Using a text file as autocomplete source

Hello experts!

I have a long list of foreign words (mostly names) stored in a text file generated via spell checking, which means some are added from time to time, those words are added one per line, many of those words are a royal pain to type, therefore it would be sweet to be able to get some auto-completion here. (I have to translate a lot of books from English to Spanish, so you can imagine)

How can I use that long word list as the source for autocompletion in a textbox?

Visual Basic.NET

Last Comment
kaufmed

8/22/2022 - Mon
kaufmed

Here's one method:
Dim autocompleteList As New List(Of String)

End While
End Using

Me.textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
Me.textBox1.AutoCompleteCustomSource = autocompleteList

SOLUTION
TheLastFantasy

Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
Get an unlimited membership to EE for less than $4 a week. Unlimited question asking, solutions, articles and more. ASKER jorgemgonzalez Ok. I tried both ways, but I might be missing something, my text box doesn't show any suggestions. Should I do anything else for this to work? What triggers the suggestions? kaufmed Did you set the AutoCompleteMode? Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC! Walt Forbes ASKER jorgemgonzalez Yes i did, your corrected code I added to the Form1_Load, whether on load or on text changed I see no results at all. TheLastFantasy You have to add something to the form load event: Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load MyBase.KeyPreview = True End Sub That should do it! TLF kaufmed @TheLastFantasy I didn't have to add that for my example. Here is my complete sample: Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim autocompleteList As New System.Windows.Forms.AutoCompleteStringCollection Using reader As New System.IO.StreamReader("file.txt") While Not reader.EndOfStream autocompleteList.Add(reader.ReadLine()) End While End Using Me.TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource Me.TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest Me.textBox1.AutoCompleteCustomSource = autocompleteList End Sub End Class  untitled.PNG file.txt Get an unlimited membership to EE for less than$4 a week.
Unlimited question asking, solutions, articles and more.
jorgemgonzalez

Still doesnt work.
The text box in my case is a multtiline text box, would that somehow be the problem with your approaches?
kaufmed

I don't believe AutoComplete works with Multiline TextBoxes.