ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

How to Create an AutoComplete in the ComboBox in VB.Net and MySQL Database

In this tutorial, I will teach you how to create an autocomple combobox in vb.net and MySQL database. The function of this is, when you type the first record in the combobox, it will automatically suggest and append. That you don’t have to click anymore the dropdown and scroll down the list of records that you’re going to select.

So, Let’s Begin:

Open the Visual Basic and Create a new Windows Form Application. Then, set the Form just like this.
autocompletecomboboxform1
After setting up the Form, double click it and set the connection of MySQL Database to Visual Basic. After that, declare all the classes that are needed above the Form1_Load.

  1. 'SET THE CONNECTION MYSQL DATABASE TO VISUAL BASIC.
  2.     Dim con As MySqlConnection = New MySqlConnection("server=localhost; user id=root; password=; database=dbmember")
  3.     'A SET OF COMMAND IN MYSQL
  4.     Dim cmd As New MySqlCommand
  5.     'SET A CLASS THAT SERVE THE BRIDGE BETWEEN A DATASET AND DATABASE FOR SAVING AND RETRIEVING DATA.
  6.     Dim da As New MySqlDataAdapter
  7.     'SET A CLASS THAT CONSIST A COMPLETE SET OF DATA
  8.     Dim ds As New DataSet

In the Form1_Load, set up a method for filling data in the ComboBox.

  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         'OPENING THE CONNECTION
  3.         con.Open()
  4.         'SET A QUERY FOR RETRIEVING DATA
  5.         Dim sqlquery As String = "select * from member"
  6.         'IT HOLDS THE DATA TO BE EXECUTED
  7.         With cmd
  8.             .Connection = con
  9.             .CommandText = sqlquery
  10.         End With
  11.         'FILLING THE DATA IN THE TABLE
  12.         da.SelectCommand = cmd
  13.         ds = New DataSet
  14.         da.Fill(ds, "member")
  15.         'GETTING THE DATASOURCE OF THE COMBOBOX
  16.         ComboBox1.DataSource = ds.Tables(0)
  17.         'SET THE FIELD IN THE TABLE TO BE DISPLAY IN THE COMBOBOX
  18.         ComboBox1.DisplayMember = "name"
  19.         'CLOSING THE CONNECTION
  20.         con.Close()
  21.         da.Dispose()
  22.     End Sub

After that, go back to the Form Design. Click the ComboBox and go the the Properties. In the properties, hit the “AutoCompleteMode” and select “SuggestAppend”. Then, hit again the “AutoCompleteSource” and select “ListItems”.
autocompletecomboboxform2

Now, press F5 on the keyboard to run your project.

You can download the complete sourcecode. Just click the code file.

The database of the project is in here

DOWNLOAD HERE

Facebook Comments

Check Your Domain Ranking

12 Comments

Add a Comment
  1. It’s awesome in favor of me to have a web page, which is valuable for my know-how.
    thanks admin

    1. Your welcome. And I will be more happy your going to share this site to your friends who is learning and willing to learn programming.

  2. I read this post completely about the comparison of latest and previous technologies, it’s awesome article.

  3. I believe this is among the most important info for me. And i am glad studying your article. However should commentary on some basic issues, The website style is ideal, the articles is in point of fact excellent : D. Good activity, cheers

  4. I am genuinely thankful to the holder of this web page who has shared this great article at at this time.

  5. This excellent website definitely has all of the info I needed concerning this subject and didn’t know who to ask.

  6. At this time I am going to do my breakfast, when having my breakfast coming yet again to read further news.

  7. What’s up, everything is going well here and ofcourse every one is sharing information, that’s actually fine, keep up writing.

  8. Hi! I could have sworn I’ve been to your blog before but after looking at a few of the posts I realized it’s new to me. Regardless, I’m certainly happy I found it and I’ll be bookmarking it and checking back often!

  9. Hi there, I wish for to subscribe for this web site to take most recent updates, so where can i do it please assist.

  10. Hi there, after reading this amazing post i am too glad to share my familiarity here with mates.

  11. Fastidious answer back in return of this matter with solid arguments and telling the whole thing about that.

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!