Results 1 to 5 of 5

Thread: [RESOLVED] How to add autocomplete search to textbox from database field?

  1. #1

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Resolved [RESOLVED] How to add autocomplete search to textbox from database field?

    Hi…

    I want to add autocomplete search feature to my application So when I type the first characters of the search key in the textbox, a drop list appear of suggested data from required field and the results list became lass as the entered characters match the search key “same idea of Google search toolbar”

    The application created using: VB2008 & MS Access .mdb
    Table name: store
    Table field name for search: Item Part Number

    This is my form search codes
    Code:
    Imports System.Data
    Imports System.Data.OleDb
    
    
    Public Class Form2
        Dim frm As New Form1
        Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source =" & Application.StartupPath & "\data.mdb"
        Dim Conn As New OleDbConnection(ConStr)
        Dim DataSet1 As New DataSet
        Dim SQLstr As String
        Dim m As String
    
    
        Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    
            DataSet1 = New DataSet
    
            Static m As Integer = 0
            If tbSearch.Text = Trim("") Then Exit Sub
            ExactSearch()
            Conn.Open()
            Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, Conn)
            DataAdapter1.Fill(DataSet1, "store")
    
            Conn.Close()
            tbSearchResulItemPartNumber.DataBindings.Clear()
            tbSearchResultItemDeascriptions.DataBindings.Clear()
            tbSearchResultItemLocation.DataBindings.Clear()
    
            tbSearchResulItemPartNumber.DataBindings.Add("Text", DataSet1, "store.Item Part Number")
            tbSearchResultItemDeascriptions.DataBindings.Add("Text", DataSet1, "store.Item Descriptions")
            tbSearchResultItemLocation.DataBindings.Add("Text", DataSet1, "store.Item Location")
    
            DataGridView1.DataSource = DataSet1
            DataGridView1.DataMember = "store"
            If Me.BindingContext(DataSet1, "store").Count = 0 Then
                MsgBox("No Result??!! ")
                Form1.Show()
                Me.Close()
            End If
    
            Exit Sub
    
        End Sub
    
        Public Sub ExactSearch()
            SQLstr = "SELECT * FROM store WHERE [Item Part Number ]= '" & tbSearch.Text & "'"
        End Sub
    
        
        Private Sub btnBACK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBACK.Click
            Me.Close()
            Form1.Show()
        End Sub
    
       
    End Class

    Kindly any suggested codes for adding autocomplete search...

    Regards…
    Last edited by HOTFIX; Nov 6th, 2008 at 10:41 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to add autocomplete search to textbox from database field?

    The TextBox class already has auto-complete functionality built in, if you'd care to look in the Properties window or read the MSDN documentation. You simply use a list that you populated from the database.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Re: How to add autocomplete search to textbox from database field?

    Thanks for advices I’ve try it but Unfortunately not working with my form
    Last edited by HOTFIX; Dec 14th, 2008 at 12:51 PM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to add autocomplete search to textbox from database field?

    That screen shot has absolutely nothing to do with auto-complete. You have to set the AutoCompleteMode to whatever's appropriate, the AutoCompleteSource to CustomSource and then assign a StringCollection containing your list of values to the AutoCompleteCustomSource. That StringCollection must be populated from your database if that's where the acceptable values are stored. You did read the relevant MSDN documentation, didn't you?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member HOTFIX's Avatar
    Join Date
    Sep 2008
    Posts
    91

    Re: How to add autocomplete search to textbox from database field?

    Quote Originally Posted by jmcilhinney
    That screen shot has absolutely nothing to do with auto-complete. You have to set the AutoCompleteMode to whatever's appropriate, the AutoCompleteSource to CustomSource and then assign a StringCollection containing your list of values to the AutoCompleteCustomSource. That StringCollection must be populated from your database if that's where the acceptable values are stored. You did read the relevant MSDN documentation, didn't you?
    You are right "jmcilhinney" I didn’t really read the MSDN documentation I just jump straight to vb.net application...

    anyway i found the Solution...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width