In this post fully learn about auto filter in DataGridView Text Box. It is very easy task. First, take DataGridView and a text box from the toolbox. After that use the below coding as per the video. AutoFilter is a great tool that we can use in many places. As with any student record, or any major store software, we use these tools to find things. This we can connect with different Colman. In particular, it Especially use with the named column.
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.IO
Public Class Form1
Private Function PopulateDataGridView() As DataTable
Dim query As String = "SELECT Name, Amount FROM Table1"
query &= " WHERE Name LIKE '%' + @Name + '%'"
query &= " OR @Name = ''"
Dim constr As String = ""
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand(query, con)
cmd.Parameters.AddWithValue("@Name", TextBox1.Text.Trim())
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
Return dt
End Using
End Using
End Using
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.DataSource = Me.PopulateDataGridView()
End Sub
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
DataGridView1.DataSource = Me.PopulateDataGridView()
End Sub
End Class