我想将表格的一栏绑定到文本框的自动完成功能,该怎么办? [英] I want to bind a column of my table to auto complete of my textbox, how can I do that ?

查看:70
本文介绍了我想将表格的一栏绑定到文本框的自动完成功能,该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2010,并且想将文本框的自动完成功能与数据库之一的列绑定.

I am using visual studio 2010 and I want to bind a textbox's auto complete  with a column of one of my tables of my database.

使用.accbd数据库数据集.

using .accbd database dataset.

推荐答案

你好

我在MSDN上有一篇文章 通过自动完成自定义源填充,保存和删除文本框中的项目.请注意,该项目是在VS2012中完成的,但其中的代码与VS2010完全兼容,您可能无法在VS2010中打开该项目,但是请尝试尝试,如果无法打开 那么您可以a)查看代码并将其应用于您的项目b)进行测试,创建一个新项目,删除Form1,然后将我项目中的文件添加到您的项目中.

I have an article on MSDN Populate, save, remove items in a TextBox via AutoComplete custom source. The project is done in VS2012 yet the code within is fully compatible with VS2010 with a caveat, you may not be able to open the project in VS2010 but do try and if you can not open it you could a) review the code and apply to your project b) for testing, create a new project, remove Form1 and then add the files from my project to your project.

要开始研究我的代码的地方,如下所示的Form1,它从MS-Access读取数据并设置一个TextBox来自动完成.

Where to start investigating my code, Form1 as shown below which reads data from MS-Access and sets up a TextBox for auto-complete.

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
        txtFirstName.AutoCompleteMode = AutoCompleteMode.SuggestAppend 
        txtFirstName.AutoCompleteSource = AutoCompleteSource.CustomSource 
        txtFirstName.AutoCompleteCustomSource = LoadFemaleNames() 

上面的代码称为

''' <summary> 
''' Load only female first names into the auto complete source 
''' </summary> 
''' <returns></returns> 
''' <remarks></remarks> 
Public Function LoadFemaleNames() As AutoCompleteStringCollection 
    Dim TheNameList As New AutoCompleteStringCollection 


    Using cn As New OleDb.OleDbConnection With 
            { 
                .ConnectionString = Builder.ConnectionString 
            } 
        Using cmd As New OleDb.OleDbCommand With {.Connection = cn} 
            cmd.CommandText = 
                <SQL> 
                    SELECT FirstName 
                    FROM FirstNames 
                    WHERE Gender = 'Female' 
                    ORDER BY FirstName; 
                </SQL>.Value 

            cn.Open() 
            Dim Reader As OleDb.OleDbDataReader = cmd.ExecuteReader 

            If Reader.HasRows Then 
                While Reader.Read 
                    TheNameList.Add(Reader.GetString(0)) 
                End While 

                Reader.Close() 

            End If 

        End Using 
    End Using 

    Return TheNameList 

End Function 



这篇关于我想将表格的一栏绑定到文本框的自动完成功能,该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆