By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,470 Members | 949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,470 IT Pros & Developers. It's quick & easy.

Filtering columns from datagridview by textbox

P: 1
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
1 Week Ago #1
Share this Question
Share on Google+
1 Reply


100+
P: 110
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
5 Days Ago #2

Post your reply

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