AutoCompleteCustomSource while Textboxtextchanged

  • Thread starter Thread starter Habib ur rehman
  • Start date Start date
H

Habib ur rehman

Guest
I am using the following code for AutoCompleteCustomSource on a textbox during TextChanged event.

Private Sub TB_Search_TextChanged(sender As Object, e As EventArgs) Handles TB_Search.TextChanged
cmd = New SqlCommand("Select Top 5 Item_Name " _
& "from Items " _
& "where Code Like '%" & TB_Search.Text.Trim & "%' " _
& "Or Item_Name Like '%" & TB_Search.Text.Trim & "%' " _
& "OrCode1 Like '%" & TB_Search.Text.Trim & "%' " _
& "Or Code2 Like '%" & TB_Search.Text.Trim & "%' " _
& "Or Code3 Like '%" & TB_Search.Text.Trim & "%' " _
& "And Status <> 'Deleted'", con)
If con.State = ConnectionState.Closed Then con.Open()
Using dr = cmd.ExecuteReader
If dr.HasRows = True And dr.Read Then
While dr.Read
With TB_Search
.AutoCompleteCustomSource.Add(dr("Item_Name"))
.AutoCompleteMode = AutoCompleteMode.SuggestAppend
.AutoCompleteSource = AutoCompleteSource.CustomSource
End With
End While
End If
End Using
End Sub

I can't add AutoCompleteCustomSource during FormLoad because I am comparing the text with multiple columns.

I am having issues with SuggestAppend and the comparison is done with Item_Name column only not with the codes columns. For example : If I type a code nothing happens while typing name selects a string auto without my choice.

I check my query in SQL Server the query is working there.




Habib Ur Rehman

Continue reading...
 
Back
Top