468,115 Members | 1,945 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,115 developers. It's quick & easy.

Filtering columns from datagridview by textbox

Expand|Select|Wrap|Line Numbers
  1. Sub fil()
  2.         Dim myconnection As New SQLiteConnection("Data Source = C:\Users\Dennis\Desktop\Final.db")
  3.         myconnection.Open()
  4.         Dim cmd As New SQLiteCommand
  5.         Dim adap As SQLiteDataAdapter = New SQLiteDataAdapter("Select * from Customers", myconnection)
  6.         Dim ds As New DataSet
  7.         adap.Fill(ds)
  8.         DataGridView1.DataSource = ds.Tables(0)
  9.         myconnection.Close()
  10.  
  11.     End Sub
  12.  
  13.     Private Sub TextBox8_TextChanged(sender As Object, e As EventArgs) Handles TextBox8.TextChanged
  14.         If TextBox8.Text = "" Then
  15.             ref()
  16.         Else
  17.             Dim dt As DataTable = DataGridView1.DataSource
  18.             dt.DefaultView.RowFilter = "[" + TextBox8.Text + "] LIKE '%" + TextBox8.Text + "%'"
  19.             fil()
  20.         End If
  21.     End Sub
here is my codee please help
i wish to filter the columns in my datagridview based on the value that i put on the textbox
Mar 18 '20 #1
1 2070
SioSio
238 128KB
I don't have an environment that uses SQLite, so the connection part of your code(fil()) is not checked.

Filtering process is;
1. Connect with database;
2. Access the data table in the dataset;
3. Show data in DataGridView;
4. Set the DataTable Filter.
Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox8_TextChanged(sender As Object, e As EventArgs) Handles TextBox8.TextChanged
  2.         If TextBox8.Text = "" Then
  3.         ref()
  4.         Else
  5.         Dim ds As New DataSet
  6.         Dim dt As DataTable
  7.         fil()
  8.         'remove "Dim ds As New DataSet" and "DataGridView1.DataSource = ds.Tables(0)" statements in fil() routine. 
  9.         dt = ds.Tables(0)
  10.         DataGridView1.DataSource = dt
  11.         dt.DefaultView.RowFilter = "[" + TextBox8.Text + "] LIKE '%" + TextBox8.Text + "%'"
  12.     End If
  13. End Sub
Mar 23 '20 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Rob | last post: by
1 post views Thread by Pattabi | last post: by
reply views Thread by sg_pl | last post: by
reply views Thread by sunny076 | last post: by
reply views Thread by David Miller | last post: by
3 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.