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)
connection.Open()


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


city_reader.Close()
End Using



EstabCityTextBox.AutoCompleteCustomSource = sStringColl
usman6062 commented: Thanks, Helped alot +0

Recommended Answers

All 4 Replies

Great Code :)

I use TableAdapter and this how i fill the autocompletecustomsource

Dim acTipeMobil As Data.IDataReader = Me.MasterTipeMobilTableAdapter.GetData.CreateDataReader
Do While acTipeMobil.Read
txtNamaTipe.AutoCompleteCustomSource.Add(acTipeMobil.Item(1))
Loop


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

nice one :)

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.