如何在C#.net windows应用程序中按后者或名称过滤datagridview的数据? [英] How to filter data of datagridview by latter or name in C# .net windows application?
本文介绍了如何在C#.net windows应用程序中按后者或名称过滤datagridview的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我想在c#.net windows应用程序中按后者或名称过滤datagridview数据,
怎么可能?
先谢谢。
Ankit Agarwal >
软件工程师
Hello,
I want to filter datagridview data by latter or name in c# .net windows application,
How can be possible?
Thanks in Advance.
Ankit Agarwal
Software Engineer
推荐答案
您可以通过多种方式过滤数据datagridview,其中一种方式如下:
You can filter data datagridview in many ways, One the the way is as below :
DataTable dt = new DataTable();
BindingSource bs = new BindingSource();
private void Form1_Load(object sender, EventArgs e)
{
dt.Columns.Add("id", typeof(int));
dt.Columns.Add("country", typeof(string));
dt.Rows.Add(new object[] { 1, "Belgium" });
dt.Rows.Add(new object[] { 2, "France" });
dt.Rows.Add(new object[] { 3, "Germany" });
dt.Rows.Add(new object[] { 4, "Spain" });
dt.Rows.Add(new object[] { 5, "Swiss" });
dt.Rows.Add(new object[] { 6, "United Kingdom" });
bs.DataSource = dt;
dataGridView1.DataSource = bs;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
bs.Filter = string.Format("country LIKE '%{0}%'", textBox1.Text);
}
欲了解更多信息,请参阅:
http://stackoverflow.com/questions/5843537/filtering-datagridview-without-changing-datasource [ ^ ]
希望这对你有所帮助!!
For more information refer:
http://stackoverflow.com/questions/5843537/filtering-datagridview-without-changing-datasource[^]
Hope this will help you!!
你可以看看这个,它应该很好地了解你应该做什么。
http://msdn.microsoft.com/en-us/library/aa480727.aspx [ ^ ]
You can have a look at this, it should give very good idea of what you should do.
http://msdn.microsoft.com/en-us/library/aa480727.aspx[^]
在这里我们可以找到解决方案
http://www.dotnetsharepoint.com/2013/08/filter-data -in-datagridview-in-c.html#.Uh76-JKfjwg [ ^ ]
Here we can find the solution
http://www.dotnetsharepoint.com/2013/08/filter-data-in-datagridview-in-c.html#.Uh76-JKfjwg[^]
这篇关于如何在C#.net windows应用程序中按后者或名称过滤datagridview的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文