VB.NET中的文本框AutoCompleteSource

编程入门 行业动态 更新时间:2024-10-23 09:40:41
本文介绍了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?

推荐答案

尝试下面的代码. 它的工作方式和更改文本框属性(自动完成模式和自动完成源) Try below code. Its working and to change the textbox properties(autocompletemode and autocompletesource) 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

我不认为AutoComplete旨在按照您描述的方式工作.通常,它可以在用户在文本框中键入内容时起作用,而不会立即提供焦点,甚至可以自动为您处理.您可以在表单的Load事件中一次性设置源,它将在用户输入时处理显示建议.将所需的代码移到表单的Load事件,然后尝试一下. 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.

更多推荐

VB.NET中的文本框AutoCompleteSource

本文发布于:2023-11-03 20:30:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556011.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   VB   NET   AutoCompleteSource

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!