VB.NET AutoComplete TextBox in a DataGridView + MySQL Database

VB.NET Tutorial : how to create DataGridView AutoComplete for one Column and data value fill from MySQL database?

VB.NET tutorial - DataGridView AutoComplete can handle Value from database like MySQL database, MS Access or SQL Server. AutoCompleteCustomSource.Add(), AutoCompleteMode, and AutoCompleteSource method can handle Autocomplete TextBox in DataGridView.

Please read :
  1. How to CRUD in a DataGridView
  2. How to Paging/Sorting in DataGridView

How AutoComplete Work?

First, we will create a connection to a Database (i use MySQL database and ODBC connection), we will connect from project to our database and get all data from database to show into a gridview, after that we can create AutoComplete source for special columns in a datagridview.

Create New Project (DataGridView AutoComplete)

Just open your visual studio and create new project rename it with "DataGridViewAutoComplete" and at the Form1.vb just Add one DataGridView to the project, and design look like this images :

AutoComplete TextBox in a DataGridView

Source code DataGridView AutoComplete


Imports System.Data.Odbc ' we can using ODBC Connection
Public Class Form1
    Dim Connect As OdbcConnection
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' create connection using ODBC connection
        Connect = New OdbcConnection("DSN=db_penjualan;MultipleActiveResultSets=True")
        ' query to Database
        Dim sql As String = "SELECT * FROM as_products"
        ' use dataadapter
        Dim da As New OdbcDataAdapter(sql, Connect)
        ' use dataset
        Dim ds As New DataSet
        ' open connection
        Connect.Open()
        da.Fill(ds, "as_products")
        ' set datasource and datamember for a datagridview
        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "as_products"
        ' close dataadapter and connection
        da.Dispose()
        Connect.Close()
    End Sub

    Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
        Dim tb As New TextBox
        Dim dt As New DataTable
        Dim cmd As New OdbcCommand
        Connect.Open()
        cmd.Connection = Connect
        cmd.CommandText = "SELECT productName from as_products"
        Dim da As New OdbcDataAdapter
        da.SelectCommand = cmd
        da.Fill(dt)
        Dim r As DataRow
        For Each r In dt.Rows

            If TypeOf e.Control Is TextBox Then
                tb = e.Control
                tb.AutoCompleteCustomSource.Add(r.Item("productName").ToString)
                tb.AutoCompleteMode = AutoCompleteMode.Suggest
                tb.AutoCompleteSource = AutoCompleteSource.CustomSource
            End If
        Next
        da.Dispose()
        cmd.Dispose()
        Connect.Close()
    End Sub
End Class

Just press "F5" key and tell me what happend

If you're still confused with this tutorial, you can watch Video tutorial above.

Video tutorial DataGridView AutoComplete



Download Full source code DataGridView AutoComplete

COMMENTS

Next Recomended


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,84,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,5,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: VB.NET AutoComplete TextBox in a DataGridView + MySQL Database
VB.NET AutoComplete TextBox in a DataGridView + MySQL Database
VB.NET Tutorial : how to create DataGridView AutoComplete for one Column and data value fill from MySQL database?
https://4.bp.blogspot.com/-ypqKp8AfkCA/V6NYcpSy7LI/AAAAAAAACMo/9hbypCR9tj840vnaO_wS57ihsZcmeLb2gCLcB/s320/AUTOCOMPLETE-DATAGRIDVIEW.png
https://4.bp.blogspot.com/-ypqKp8AfkCA/V6NYcpSy7LI/AAAAAAAACMo/9hbypCR9tj840vnaO_wS57ihsZcmeLb2gCLcB/s72-c/AUTOCOMPLETE-DATAGRIDVIEW.png
KODE AJAIB
https://www.kodeajaib.com/2016/08/autocomplete-textbox-in-datagridview.html
https://www.kodeajaib.com/
https://www.kodeajaib.com/
https://www.kodeajaib.com/2016/08/autocomplete-textbox-in-datagridview.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy