在C#中过滤datagridview [英] Filter datagridview in C#

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

问题描述

如何在C#中过滤datagridview?


我尝试过:



我增值

How can i do filter datagridview in C#

What I have tried:

I add value

dataGridView1.Rows[setr].Cells[1].Value = values[0];




I dont use datagrid source

推荐答案

其中一种方法是,不是向datagridview添加行,而是将数据行添加到数据表中,然后一旦数据表准备就绪,使其成为你的datagridview的数据源。



类似的东西 -

One of the way is to, instead of adding rows to the datagridview, add datarows to a datatable and then once datatable is ready make it the datasource of your datagridview.

Something like-
DataTable table = new DataTable();
table.Columns.Add("Name", typeof(String));
table.Columns.Add("...", typeof(String));


foreach (var element in list)
   table.Rows.Add(element.Name, element.Something);


dataGridView1.DataSource = table1;
table.DefaultView.RowFilter = "Name Like '...'";





如需详细解答,请查看stackoverflow中的以下主题 -

c# - 过滤没有数据绑定的DataGridView - Stack Overflow [ ^ ]



希望,有帮助:)



For detailed answer, check the following thread in stackoverflow-
c# - Filtering an DataGridView that doesn't have databinding - Stack Overflow[^]

Hope, it helps :)


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

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