将结果从文本框过滤到DataGridView [英] Filtering results from textbox to DataGridView

查看:71
本文介绍了将结果从文本框过滤到DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从现有的DataGridView表中过滤/搜索一些结果。除了一个领域,我已经完成了大部分工作。这是我的DataGridView表产品ID的第一个字段,它是一个Int数据类型字段。所以我认为它需要在Int Value to System.String上进行一点转换..但是我没有得到如何解决这个问题..任何人都可以帮助我..

I want to filter/search some results from my existing DataGridView Table. I have done most of them except one field. That's the first field of my DataGridView Table "Product ID" it's an Int data type field. So I think it needs a bit conversion on the Int Value to System.String.. but I'm not getting how to fix that.. Can any one please help me..

private void txtSearch_TextChanged(object sender, EventArgs e)
{
    try 
    {
        DataView DV = new DataView(dbdataset);
        DV.RowFilter = string.Format("Convert[Product ID, System.String] LIKE '%{0}%' OR [Product Name] LIKE '%{0}%' OR [Brand Name] LIKE '%{0}%' OR [Pro. Size ID] LIKE '%{0}%'", txtSearch.Text);
        dgView.DataSource = DV;
    }
     catch (Exception ex)
    {
        Error_txt.Text = ex.Message;
    }

}



它出错了


It gives an error

Syntax error: Missing operand after '[Product ID, System.String]' operator.

推荐答案

更改

change
Convert[Product ID, System.String] LIKE '%{0}%' 



to


to

Convert([Product ID], 'System.String') LIKE '%{0}%' 


您可以通过这种方式放置行过滤器

You can put row filter on this way
DV.RowFilter = string.Format("[Product ID]'{0}' OR [Product Name]='{0}' OR [Brand Name]='{0}' OR [Pro. Size ID]='{0}'", txtSearch.Text);


这篇关于将结果从文本框过滤到DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆