本文介绍了VB.NET中的文本框AutoCompleteSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码来自一个类:
Below is the code comes from a Class:
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
以下是来自Form的代码:
Below is the code comes from Form:
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
当我将光标放在txtVendor文本框中时,我希望自动完成功能会生成供应商列表.但是,出乎意料的是,当我进入文本框时,我立即收到错误消息"ERROR CREATING WINDOW HANDLE".错误显示在txtVendor.AutoCompleteMode = AutocompleteMode.Suggest语句上.
有人可以帮忙吗?
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?
推荐答案
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
这篇关于VB.NET中的文本框AutoCompleteSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!