1 Attachment(s)
[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
Re: How to make Seach in the TextBox as it did in Google TextBox
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:
Dim recName As DB.tblNameRow
Re: How to make Seach in the TextBox as it did in Google TextBox
Where do you get the values in the suggestion box ?
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?
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
Re: How to make Seach in the TextBox as it did in Google TextBox
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 ?
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
Re: How to make Seach in the TextBox as it did in Google TextBox
Quote:
Originally Posted by
snakeman
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?
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))
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:
Dim conn As New OleDbConnection()
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source =" & Application.StartupPath & "\DataBaseName.mdb "
Dim sql As String = " Select * from Table1"
Dim dp As New OleDbDataAdapter(sql, conn)
Dim rs As New DataSet
dp.Fill(rs, "Table1")
conn.Open()
TextBox1.Text = rs.Tables("Table1").Rows(0).Item(0)
TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
For x As Integer = 0 To 100
rs.Tables("Table1").Columns("Name")
TextBox1.AutoCompleteCustomSource.Add(rs.Tables("Table1").Columns("Name"))
Next
conn.Close()
Re: How to make Seach in the TextBox as it did in Google TextBox
Quote:
Originally Posted by
nader
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:
Dim conn As New OleDbConnection()
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source =" & Application.StartupPath & "\DataBaseName.mdb "
Dim sql As String = " Select * from Table1"
Dim dp As New OleDbDataAdapter(sql, conn)
Dim rs As New DataSet
dp.Fill(rs, "Table1")
conn.Open()
TextBox1.Text = rs.Tables("Table1").Rows(0).Item(0)
TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
For x As Integer = 0 To 100
rs.Tables("Table1").Columns("Name")
TextBox1.AutoCompleteCustomSource.Add(rs.Tables("Table1").Columns("Name"))
Next
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:
Dim conn As New OleDbConnection()
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source =" & Application.StartupPath & "\DataBaseName.mdb "
Dim sql As String = " Select * from Table1"
dim cmd as oledbcommand (sql,conn)
Dim dp As New OleDbDataAdapter
dp.selectcommand= cmd
Dim rs As New DataSet
dp.Fill(rs, "Table1")
TextBox1.Text = rs.Tables("Table1").Rows(0).Item(0)
TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
For x As Integer = 0 To rs.tables("table1").Rows.Count - 1
TextBox1.AutoCompleteCustomSource.Add(rs.tables("table1").Rows(x).item("name"))
Next
try to understand what i changed
if you didn't understand anything please tell me :)
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.
Re: How to make Seach in the TextBox as it did in Google TextBox
what do you want exactly?
1 Attachment(s)
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.
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()
Re: [RESOLVED] How to make Seach in the TextBox as it did in Google TextBox