如何过滤Datagridview [英] How Do I Filtering Datagridview

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

问题描述

hi
用于过滤DataGridView我写这段代码但不行吗?



hi for filtering DataGridView i write this code but not work why ?

BindingSource bs = new BindingSource();
                   bs.DataSource = dgvSPage.DataSource;
       private void textBox1_TextChanged(object sender, EventArgs e)
       {
           try
           {

               if(dgvSPage.Rows.Count>0)
               {

                  bs.Filter =  string.Format("Id = {0} ", txtsearchId.Text);
                  dgvSPage.DataSource = bs;
               }

               if (txtsearchId.Text == string.Empty)
               {
                   bs.RemoveFilter();
                   bs.Filter = null;
                   dgvSPage.DataSource = bs;
               }
           }
           catch (Exception er)
           {
               MessageBox.Show(er.Message + "\n" + er.Source + "\n" + er.StackTrace + "\n" + er.TargetSite);
               throw;

           }
       }





如何过滤datagridview ??



How filter datagridview??

推荐答案

尝试以这种方式编写过滤器:



Try writing your filter this way:

bs.Filter=String.Format("Id LIKE '%{0}%'", txtsearchId.Text):





(添加'%%')。如果这不起作用:



MSDN文档 https://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.filter(VS.90)的.aspx [ ^ ]说:



只有实现IBindingListView接口的基础列表才支持过滤。




所以也许你的数据源有问题?



(added '% %'). if this doesn't work:

The MSDN Documentation https://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.filter(VS.90).aspx[^] says:

Only underlying lists that implement the IBindingListView interface support filtering.


so maybe it's a problem with your datasource ?


这篇关于如何过滤Datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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