Results 1 to 18 of 18

Thread: [RESOLVED] How to make Seach in the TextBox as it did in Google TextBox

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Resolved [RESOLVED] How to make Seach in the TextBox as it did in Google TextBox

    I'm using vb2005 and Ms DB Access.
    Is that possible to make search as it did in Google site as it show in the pic Below
    Attached Images Attached Images  

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to make Seach in the TextBox as it did in Google TextBox


  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: How to make Seach in the TextBox as it did in Google TextBox

    I read the example, but I didn't understand this line of code:
    vb Code:
    1. Dim recName As DB.tblNameRow

  4. #4
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: How to make Seach in the TextBox as it did in Google TextBox

    Where do you get the values in the suggestion box ?
    Please mark you thread resolved using the Thread Tools as shown

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: How to make Seach in the TextBox as it did in Google TextBox

    I wrote down the values in the item of ComboBox.
    does this you mean?

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: How to make Seach in the TextBox as it did in Google TextBox

    You could do something like

    Code:
     Try
                'Get the values from Database and Add in the Collection
                Dim aCol As New AutoCompleteStringCollection
                aCol.Add("Line1")
                aCol.Add("vbforums.com")
                TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
                TextBox1.AutoCompleteCustomSource = aCol
                TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
            Catch ex As Exception
    
            End Try
    Please mark you thread resolved using the Thread Tools as shown

  7. #7
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Re: How to make Seach in the TextBox as it did in Google TextBox


  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: How to make Seach in the TextBox as it did in Google TextBox

    do I have to creat DataSet and call the data from ?

  9. #9
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Re: How to make Seach in the TextBox as it did in Google TextBox

    is the data that you want to be in the auto complete source is from database??
    or from a control.
    if the data is from a combo box then it will be like this
    Code:
           TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
            TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
            For x As Integer = 0 To 100
                ComboBox1.Items.Add(x)
                TextBox1.AutoCompleteCustomSource.Add(ComboBox1.Items(x))
            Next
    if else please tell us.
    hope this helps

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: How to make Seach in the TextBox as it did in Google TextBox

    Quote Originally Posted by snakeman View Post
    is the data that you want to be in the auto complete source is from database??
    or from a control.
    if the data is from a combo box then it will be like this
    Code:
           TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
            TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
            For x As Integer = 0 To 100
                ComboBox1.Items.Add(x)
                TextBox1.AutoCompleteCustomSource.Add(ComboBox1.Items(x))
            Next
    if else please tell us.
    hope this helps
    In wich event of TextBox I must to insert this code?

  11. #11
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Re: How to make Seach in the TextBox as it did in Google TextBox

    the above CODE IS ONLY FOR TEST (PUT IT IN A BUTTON CLICK EVENT AND TRY IT)
    AGAIN IT IS ONLY FOR TEST

    let's say if you want the textbox autocomplete list will be the combobox values
    then you can put this in the form load event:-

    Code:
          TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
            TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
    and in the event that you use to add values to the combo box you can use:-
    Code:
    TextBox1.AutoCompleteCustomSource.Add(ComboBox1.Items(x))

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: How to make Seach in the TextBox as it did in Google TextBox

    I tried the code in last previous in post #9, and it worked well with me.
    I created database Ms access called "DataBaseName" with Table1 including three fileds:Name,Place,Mobile.

    I inserted this code in the Form load to search the data in DataBaseName in filed "Name", but I don't know how to complete it. May help please.

    vb Code:
    1. Dim conn As New OleDbConnection()
    2.         conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source =" & Application.StartupPath & "\DataBaseName.mdb "
    3.         Dim sql As String = " Select * from Table1"
    4.         Dim dp As New OleDbDataAdapter(sql, conn)
    5.         Dim rs As New DataSet
    6.         dp.Fill(rs, "Table1")
    7.         conn.Open()
    8.         TextBox1.Text = rs.Tables("Table1").Rows(0).Item(0)
    9.         TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
    10.         TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
    11.         For x As Integer = 0 To 100
    12.             rs.Tables("Table1").Columns("Name")
    13.             TextBox1.AutoCompleteCustomSource.Add(rs.Tables("Table1").Columns("Name"))
    14.         Next
    15.         conn.Close()

  13. #13
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Re: How to make Seach in the TextBox as it did in Google TextBox

    Quote Originally Posted by nader View Post
    I tried the code in last previous in post #9, and it worked well with me.
    I created database Ms access called "DataBaseName" with Table1 including three fileds:Name,Place,Mobile.

    I inserted this code in the Form load to search the data in DataBaseName in filed "Name", but I don't know how to complete it. May help please.

    vb Code:
    1. Dim conn As New OleDbConnection()
    2.         conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source =" & Application.StartupPath & "\DataBaseName.mdb "
    3.         Dim sql As String = " Select * from Table1"
    4.         Dim dp As New OleDbDataAdapter(sql, conn)
    5.         Dim rs As New DataSet
    6.         dp.Fill(rs, "Table1")
    7.         conn.Open()
    8.         TextBox1.Text = rs.Tables("Table1").Rows(0).Item(0)
    9.         TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
    10.         TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
    11.         For x As Integer = 0 To 100
    12.             rs.Tables("Table1").Columns("Name")
    13.             TextBox1.AutoCompleteCustomSource.Add(rs.Tables("Table1").Columns("Name"))
    14.         Next
    15.         conn.Close()
    first where is oledbcommand ???????????????/
    second why you put 100 in the loop????
    third why do you open and close the connection
    you are not dealing with the db directly actually you are dealing with the dataset so you don't need to open and close the connection in this point
    because when the adapter filled the dataset the adapter automatically opened and closed the connection
    fourth what is this????????????
    Code:
                rs.Tables("Table1").Columns("Name")
    thats wrong.

    this is the right thing:-
    vb Code:
    1. Dim conn As New OleDbConnection()
    2.         conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source =" & Application.StartupPath & "\DataBaseName.mdb "
    3.         Dim sql As String = " Select * from Table1"
    4.         dim cmd as oledbcommand (sql,conn)
    5.         Dim dp As New OleDbDataAdapter
    6.         dp.selectcommand= cmd
    7.         Dim rs As New DataSet
    8.         dp.Fill(rs, "Table1")
    9.  
    10.         TextBox1.Text = rs.Tables("Table1").Rows(0).Item(0)
    11.         TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
    12.         TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
    13.  
    14.         For x As Integer = 0 To rs.tables("table1").Rows.Count - 1
    15.             TextBox1.AutoCompleteCustomSource.Add(rs.tables("table1").Rows(x).item("name"))
    16.         Next
    try to understand what i changed
    if you didn't understand anything please tell me

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: How to make Seach in the TextBox as it did in Google TextBox

    It has succedd with me, but the first one (where the values are written in the combobox), when I load the form where I inserted the code it didn't show the data in the textbox only when I write in the textbox, but in this code ( where the values is written in the Db), whe I load the form it show the first values in the textbox how can I make it like previous code.

  15. #15
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Re: How to make Seach in the TextBox as it did in Google TextBox

    what do you want exactly?

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: How to make Seach in the TextBox as it did in Google TextBox

    Here is a pic
    the frist one it show the text imeadiatley in the texbox( which use the code in the post #13), the second( which use the code in the post #9), it didn't show the text only after write in the textbox.
    Attached Images Attached Images  

  17. #17
    Hyperactive Member snakeman's Avatar
    Join Date
    Aug 2006
    Posts
    351

    Re: How to make Seach in the TextBox as it did in Google TextBox

    because i assigned a default value to the textbox.
    when i was dealing with the DB i Used this :-
    Code:
          TextBox1.Text = rs.Tables("Table1").Rows(0).Item(0)
    so when dealing with the combo box :-
    Code:
            TextBox1.Text = combobox1.Items(0).ToString()

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: [RESOLVED] How to make Seach in the TextBox as it did in Google TextBox

    Thank you for help!

Tags for this Thread

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