Click here to Skip to main content
16,016,882 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello!
I am using Microsoft Visual Studio 2005.

How do I filter a DataGridView while typing on textbox?
This is my table right now:
VB
username     password     rated
  abc          123          y
  def          456          y
  ghi          879          y
  xyz          111          n
  uvw          222          n


So when i type on my textbox "abc" i want to automatically filter the DGV who has that username. So it will only show:
VB
username     password     rated
  abc           123         y


Thanks in advance! :)

<edit> I did not make any bindingsource.
this is my code:
VB
Dim con As New clsConn
Dim sqlstring As String

VB
Public Sub LoadQueue()
    sqlstring = "SELECT * FROM Users"
    DGVqueue.DataSource = con.ReturnQuery(sqlstring)
End Sub


My Class:
VB
Imports System.Data
Imports System.Data.SqlClient

Public Class clsConn
    Dim connectionString = "Data Source=******\SQLEXPRESS; Initial Catalog=MySystem; Integrated Security=true"
    Dim sqlCommandQS As SqlCommand
    Dim sqlAdapterQS As SqlDataAdapter
    Dim sqlBuilderQS As SqlCommandBuilder
    Dim sDsQS As DataSet
    Dim sTableQS As DataTable
    Dim connectionQS As New SqlConnection(connectionString)

    Function ReturnQuery(ByRef strsql As String) As DataTable
        Try
            Dim connectionQS As New SqlConnection(connectionString)
            connectionQS.Open()
            sqlCommandQS = New SqlCommand(strsql, connectionQS)
            sqlAdapterQS = New SqlDataAdapter(sqlCommandQS)
            sqlBuilderQS = New SqlCommandBuilder(sqlAdapterQS)
            sDsQS = New DataSet()

            sqlAdapterQS.Fill(sDsQS)
            sTableQS = sDsQS.Tables(0)
            connectionQS.Close()
            Return sTableQS
        Catch ex As Exception
            connectionQS.Close()
            Return Nothing
            MsgBox(ex.Message)
        End Try
    End Function
End Class
Posted
Updated 14-May-14 16:53pm
v3
Comments
DamithSL 14-May-14 22:43pm    
hoy you bind the gridview? update the question with the code
charliedev 14-May-14 22:48pm    
i didn't make any bindingsource

1 solution

try like below in your textbox textChanged event
VB
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        sqlstring = "SELECT * FROM Users [username] Like '%" & TextBox1.Text) & "%'""
        DGVqueue.DataSource = con.ReturnQuery(sqlstring)
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900