如何过滤Datagridview? [英] How Filtering Datagridview?

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

问题描述

你好!

从lasttopic我有关于过滤行DataGridView的问题。

这是关于主题的链接,在这里你可以看到形状DataGrig:



Hello!
From lasttopic i have question about filtering rows DataGridView.
This is link on topic, where you can see how shapes DataGrig:

ListCards.DataSource = BLL.Cards.GetListCards(); (View layer)





手动MSDN我发现以下内容:





At manual MSDN i found following:

BindingSource bs = new BindingSource();
bs.DataSource = dataGridView1.DataSource;
bs.Filter = "yourColumnName like '%" + textBox1.Text + "%'";
dataGridView1.DataSource = bs;



_________________________________

在第一个我想填充网格并显示它:ListCards.DataSource = BLL.Cards.GetListCards();

当我向TextBox输入文本时,我想按名称网格进行排序以及如何制作它?

试试这样:

BindingSource bs = new BindingSource();




_________________________________
In the first i want to fill Grid and show it: ListCards.DataSource = BLL.Cards.GetListCards();
When i enter text to TextBox i want to do sort by Name Grid and how make it?
Try such:
BindingSource bs = new BindingSource();

<pre lang="c#">

....活动

bs.DataSource = BLL.Cards.GetListCards();

bs.Filter =yourColumnName like''%+ textBox1.Text +%'';

ListCards.DataSource = bs;

....Event
bs.DataSource = BLL.Cards.GetListCards();
bs.Filter = "yourColumnName like ''%" + textBox1.Text + "%''";
ListCards.DataSource = bs;

推荐答案

查看此Junoli ...



http://msdn.microsoft.com/en-us /library/system.windows.forms.bindingsource.filter.aspx [ ^ ]
Check this Junoli...

http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.filter.aspx[^]


所以,我做了:

So, i made:
BindingList<Cards.Model.Cards> filtered = new BindingList<Cards.Model.Cards>(list.Where(
                                 p => p.Username.Contains(""+textBox1.Text+"")).ToList());
            ListCards.DataSource = filtered;


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

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