Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have this code to make a datagrid search with a textbox, it works fine

private void txtSearch_TextChanged(object sender, EventArgs e)
  {
      BindingSource bs = new BindingSource();
      bs.DataSource = dataGrid1.DataSource;
      bs.Filter = "BARCODE like '%" + txtSearch.Text + "%'";
      dataGrid1.DataSource = bs;
  }


but now, i need to delete always 0000 (four 0) at the start of the search to find the reference on my datagrid, for example:


if I text in textbox :
000012345

datagrid shows search =
12345 


thanks

What I have tried:

i tried to adapt this code but i cant
BindingSource bs = new BindingSource();
bs.DataSource = dataGrid1.DataSource;
bs.Filter = "BARCODE like '%" + txtSearch.Text + "%'";
dataGrid1.DataSource = bs;
Posted
Updated 7-Jan-18 17:57pm
Comments
Maciej Los 7-Jan-18 6:51am    
Sorry, but your question is not clear. Note that we don't see your screen and we can't read in your mind. Please, be more specific and provide proper information.
drvfn 7-Jan-18 17:57pm    
I have a textbox for make searchs in a specific column, but now i have to modify This code to add always 0000 at the start of the search for example:

I need that, If i wrote 00001234 in the textbox it would find 1234 on that column. All the numbers on my column has 4 digits, but the bar code i use to find has 8 digits becouse of that , in the search i need to add four ceros.

Please, someone can help me?
Karthik_Mahalingam 7-Jan-18 23:51pm    
use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.

1 solution

Quote:
I have a textbox for make searchs in a specific column, but now i have to modify This code to add always 0000 at the start of the search for example:

I need that, If i wrote 00001234 in the textbox it would find 1234 on that column. All the numbers on my column has 4 digits, but the bar code i use to find has 8 digits becouse of that , in the search i need to add four ceros.


try
   BindingSource bs = new BindingSource();
bs.DataSource = dataGrid1.DataSource;
        string keyword = "0000" + txtSearch.Text.Trim();
bs.Filter = "BARCODE like '%" + keyword + "%'";
dataGrid1.DataSource = bs;
 
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