Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
See more:
I tired to filter a datagridview using a textbox, the textbox is contained in a tabpage.
Posted
Updated 23-Jan-19 20:24pm

I solve my self....

C#
try
           {
               //this code is used to search Name on the basis of txttxtSearchItem.text
               ((DataTable)DGVExistingItem.DataSource).DefaultView.RowFilter = string.Format("Name like '%{0}%'", txtSearchItem.Text.Trim().Replace("'", "''"));
           }
           catch (Exception) { }
 
Share this answer
 
v2
Comments
Member 10738387 5-Jun-19 6:27am    
is there any way to implement more than one column.
connection.Open();
SqlDataAdapter da = new SqlDataAdapter("Select ColumnName1,ColumnName2 from TableName Where ColumnName = '" + textBox1.Text + "'", connection);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource= dt;
connection.Close();

Try This..........:-)
 
Share this answer
 
Comments
Shambhoo kumar 11-Jan-13 8:11am    
Hey mam i don't want to use SQL commamnd o0k...
//write this in the textchanged event of your text box.
if(yourtxtboxname.Text.Trim!="")
{
OleDBConnection con=new OleDBConnection(yourconnection string);
OleDBDataAdapter da=new OleDBDataAdapter("Select * From TableName Where ColumnName Like'%" + textBox1.Text + "%'", con);
DataSet ds=new DataSet();
da.Fill(ds);
DGV1.DataSource=ds.Table[0].DefaultView;
}

//I hope This Help You.
//Tested With VS2017 On Access2010DBS.
//Ehsan.
 
Share this answer
 
Comments
Richard Deeming 2-Mar-18 10:03am    
Asked, answered, and solved over FIVE YEARS AGO.

And your solution copies the SQL Injection[^] vulnerability from solution #1.

Stick to answering recent questions, and avoid posting code with major security vulnerabilities in it.

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