如何通过在文本框中输入文本来过滤数据网格视图? [英] How to filter a datagridview by entering a text in textbox?

查看:53
本文介绍了如何通过在文本框中输入文本来过滤数据网格视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们



我有一个包含很多条目的dataGridView。我想用文本框中的文本过滤所有条目,例如:



TextBox text =Mr.,当我点击搜索按钮时, dataGridView中的整个列表只显示标题为'Mr.'的条目。





有人可以帮助我吗?





感谢您的帮助。

valentigra

Hey guys

I have a dataGridView with many entries. I would like to filter all entries with a text from a textbox, example:

TextBox text = "Mr.", when I click the button "Search", the whole list in dataGridView shoult only show entries with the title like 'Mr.'.


Can anyone help me, please?


Thanks for every help.
valentigra

推荐答案

在按钮的click事件中检查文本框的内容并使用内容过滤绑定到DGV的基础集合



您可能需要拥有ALL集合并将其过滤到新集合中以支持清除过滤器功能。
In the click event of the button check the content of the textbox and use the content to filter the underlying collection that is bound to the DGV

You may need to have an ALL collection and filter that into a new collection to support the clear filter functionality.


检查这个

filter-data-in-datagridview-c-sharp





使用rowfilter过滤



filtering-datagridview /



http://msdn.microsoft.com/en-us/library/system.data.dataview.rowfilter( v = vs.110).aspx



http://www.csharp-examples.net/dataview-rowfilter/
check this
filter-data-in-datagridview-c-sharp


filtering using rowfilter

filtering-datagridview/

http://msdn.microsoft.com/en-us/library/system.data.dataview.rowfilter(v=vs.110).aspx

http://www.csharp-examples.net/dataview-rowfilter/


嗨试试这个



hi try this one

private void TextBox_TextChanged(object sender, EventArgs e)
{
    (DataGridView.DataSource as DataTable).DefaultView.RowFilter =
    string.Format("Name LIKE '{0}%' OR Name LIKE '% {0}%'", TextBox.Text);
}


这篇关于如何通过在文本框中输入文本来过滤数据网格视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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