Click here to Skip to main content
15,916,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below is the code comes from a Class:

VB
Public Function GetVendorNames() As AutoCompleteStringCollection
        Dim X As New AutoCompleteStringCollection
        MyBase.ConnectToDB()
        Dim cmd As New SqlClient.SqlCommand("select distinct vendor from product", Cn)
        Dim dr As SqlClient.SqlDataReader
        dr = cmd.ExecuteReader
        While dr.Read
            X.Add(dr.Item(0).ToString)
        End While
        MyBase.DisconnectFromDB()
        cmd.Dispose()
        cmd = Nothing
        Return X
    End Function

Below is the code comes from Form:
VB
Private Sub Autopopulate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtVendor.GotFocus
        Dim p As New Product
        txtVendor.AutoCompleteSource = AutoCompleteSource.CustomSource
        txtVendor.AutoCompleteCustomSource = p.GetVendorNames
        txtVendor.AutoCompleteMode = AutoCompleteMode.Suggest
        p = Nothing
    End Sub


When I place my cursor in the txtVendor Textbox, I expect autocomplete feature should generate the list of vendors. But, unexpectedly I am given an error as "ERROR CREATING WINDOW HANDLE" instantly when I enter into the text box. The error is showing on txtVendor.AutoCompleteMode=AutocompleteMode.Suggest statement.

Could someone help on this?
Posted
Updated 6-Jan-12 2:36am
v3

Try below code.
Its working and to change the textbox properties(autocompletemode and autocompletesource)
VB
 Cn.Open()
Dim dt As New DataTable
Dim da As New OleDbDataAdapter("select ...........", Cn)
da.Fill(dt)
Dim row As DataRow
txtvendor.AutoCompleteCustomSource.Clear()
For Each row In dt.Rows
   txtvendor.AutoCompleteCustomSource.Add(row.Item(0).ToString())
Next
 
Share this answer
 
I don't believe AutoComplete is intended to work the way you've described it. Typically it works as the user types in the textbox, not as soon as the focus is given, and even that is automatically handled for you. You can set the source up one time in the Load event of the form and it will handle showing the suggestions as the user types. Move the code you have to the Load event of the form and then try it out.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900