在文本框C#中调整搜索
您好b $ b
我有这个代码用文本框进行数据网格搜索,工作正常
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;
}
但现在,我需要在开头时始终删除0000(四个0)搜索我的数据网格上的参考,例如:
如果我在文本框中发短信:
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显示search =
datagrid shows search =
12345
谢谢
我尝试了什么:
i尝试调整此代码但是我不能
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;
我有一个用于在特定列中进行搜索的文本框,但现在我必须修改此代码以在搜索开始时添加始终为0000,例如:
I需要的是,如果我在文本框中写了00001234,它会在该列上找到1234。我列上的所有数字都有4位数字,但我用来查找的条形码有8位数,因为在搜索中我需要添加4个ceros。
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
try
BindingSource bs = new BindingSource();
bs.DataSource = dataGrid1.DataSource;
string keyword = "0000" + txtSearch.Text.Trim();
bs.Filter = "BARCODE like '%" + keyword + "%'";
dataGrid1.DataSource = bs;