vb.net Access 数据库中的自动完成文本框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21018672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:23:54  来源:igfitidea点击:

Auto Complete Text Box from Access database

vb.netvisual-studioms-accessms-officems-access-2010

提问by JBithell

I have a text box "Textbox1" and a set of 30,000 words stored in an access database. I would like to set the VB Textbox1's auto complete source to the access database. How do I do this in vb.net? I am a novice programmer at present.

我有一个文本框“Textbox1”和一组存储在访问数据库中的 30,000 个单词。我想将 VB Textbox1 的自动完成源设置为访问数据库。我如何在 vb.net 中做到这一点?我目前是一个新手程序员。

回答by Vland

Sample:

样本:

From an access Database

从访问数据库

enter image description here

在此处输入图片说明

Create a DataSet in your vb project, connected to that database

在你的 vb 项目中创建一个 DataSet,连接到那个数据库

Add New Item -> Data -> DataSet

添加新项目 -> 数据 -> 数据集

In your .xsddesigner, add a new TableAdapter, connect it to your Access file, create a query.

在您的.xsd设计器中,添加一个新的 TableAdapter,将其连接到您的 Access 文件,创建一个查询。

enter image description here

在此处输入图片说明

Query and add them to the TextBox.AutoCompleteCustomSource

查询并将它们添加到 TextBox.AutoCompleteCustomSource

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'NamesDataSet.Names' table. You can move, or remove it, as needed.
    Me.NamesTableAdapter.Fill(Me.NamesDataSet.Names)

    'get my names from the dataset
    Dim myNames = From n In NamesDataSet.Names Select n.Name

    TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
    TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource

    'add names to custom list
    TextBox1.AutoCompleteCustomSource.AddRange(myNames.ToArray())
End Sub

enter image description here

在此处输入图片说明