Reputation:
I have a problem on how to search records in datagridview. This is my sample code.
Private Sub txtStit_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStit.TextChanged
Dim sqlsearch As String
sqlsearch = "SELECT * FROM tblList WHERE [Book Title] LIKE '%" & txtStit.Text & "%'"
Dim adapter As New OleDbDataAdapter(sqlsearch, con)
Dim dt As New DataTable("tblList")
adapter.Fill(dt)
DataGridView3.DataSource = dt
End Sub
Actually it works but my problem is whenever I clicked or move the cursor outside the textbox the records that I didn`t searched are showing.
thnk u guys
[visual studio 2008, mcaccess 2007]
Upvotes: 0
Views: 375
Reputation: 5369
As you understand, there is no way to appear records that you did not ask for. You asked it somehow, implicitly or explicitly. I bet you have set the datasource of the DataGridView3
using a wizard or an explicit query somewhere else. I would suggest debugging using breakpoints on different events of the application lifecycle. Using the breakpoints, you can identify where the change of the datasource happens. I would start from Form.Load
event...
Hope I helped!
Upvotes: 0
Reputation: 333
TextChanged is firing with each keystroke. Try moving it to KeyUp
If e.KeyCode = Keys.Return Then
Put your code here
End If
Upvotes: 1