Thought I'd share my code for populating the AutoCompleteCustomSource in a textbox with data from an Access table or other ODBC datasource. This works, though perhaps others have found a more elegant way. In this example, I am adding a list of city names. - Jeff

Dim sStringColl As New AutoCompleteStringCollection
Dim qryCity As String
qryCity = "SELECT DISTINCT EstabCity FROM t_Estab WHERE ISNULL(EstabCity) = 0 ORDER By EstabCity"

Using connection As New Odbc.OdbcConnection("connection string goes here")

Dim cmdCity As New Odbc.OdbcCommand(qryCity, connection)

Dim city_reader As Odbc.OdbcDataReader = cmdCity.ExecuteReader()

' Loop through the data.
While city_reader.Read()
sStringColl.AddRange(New String() {city_reader(0)})
End While

End Using

EstabCityTextBox.AutoCompleteCustomSource = sStringColl

Edited 3 Years Ago by happygeek: fixed formatting

Thanks, Helped alot

I use TableAdapter and this how i fill the autocompletecustomsource

Dim acTipeMobil As Data.IDataReader = Me.MasterTipeMobilTableAdapter.GetData.CreateDataReader
Do While acTipeMobil.Read

Are there some filling methods without looping?
those can be faster i think
anyone knows?

Thanks for sharing this cool and very helpful data.
I was looking for it and atlast found it.
Thanks once again.

This article has been dead for over six months. Start a new discussion instead.