Hi I am using the following to auto search db
Dim connString As String = My.Settings.strConn
Dim conn As New SqlConnection(connString)
Dim cmd As New SqlCommand("select firstName, existing from tenant Where (existing = 1)", conn)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
Try
conn.Open()
da.Fill(ds, "List")
Dim col As New AutoCompleteStringCollection ' From which our names will come
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)(0).ToString())
Next
ComboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
ComboBox1.AutoCompleteCustomSource = col
ComboBox1.AutoCompleteMode = AutoCompleteMode.Suggest
Catch ex As Exception
MsgBox(ex.Message)
Finally
conn.Close()
End Try
I am currently using this to populate the text boxes on the click event for the combo list I tried selectedIndex as well
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.Click
If ComboBox1.Text.Length > 0 Then
Dim connString As String = My.Settings.strConn
Dim conn As New SqlConnection(connString)
Try
conn.Open()
Dim qry As String = "select * from tenant where firstName='" + ComboBox1.Text + "'"
Dim cmd As New SqlCommand(qry, conn)
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.Read() Then
TextBoxDob.Text = dr(5)
TextBoxFirstName.Text = dr(1)
TextBoxLastName.Text = dr(2)
TextBoxId.Text = dr(0)
TextBoxPhone.Text = dr(4)
TextBoxEmail.Text = dr(3)
TextBoxNotes.Text = dr(13)
End If
dr.Close()
Catch ex As Exception
Finally
conn.Close()
End Try
Else
'do nothing
End If
End Sub
I want the text boxes to populate when a result is clicked from the drop list of the combo box at the moment
you start typing in the combo box and it starts to populate with first names then you pick one of the names from the list which is displayed in the drop down box you then have to click the box to get it to populate the text boxes.
there are two things I would like it to do one would be to display the first and last name in the combo-box if this is possible and also have the text boxes populate when a name is selected.
any help appreciated