过滤Datagridview没有数据源有1个缺乏行 [英] Filter Datagridview Without Datasource having 1 lackh rows

查看:85
本文介绍了过滤Datagridview没有数据源有1个缺乏行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在使用带有一个字符串列的datagridview和大约1个缺少Datasource为空的行,我想根据文本框文本更改事件过滤datagridview但是它花时间过滤,我的表格变成无响应状态。

 string Temp = textBox2.Text.Trim(); 
if(Temp!= string.Empty)
{
this.dataGridView1.Rows.OfType< DataGridViewRow>()。Where(r =>!r.Cells [0] .Value .ToString()。ToUpper()。包含(Temp)&&!r.Cells [0] .Value.ToString()。ToLower()。包含(Temp))。ToList()。ForEach(row => ; {if(!row.IsNewRow)row.Visible = false;});
}
其他
{
this.dataGridView1.Rows.OfType< DataGridViewRow>()。ToList()。ForEach(row => {if(!row.IsNewRow) row.Visible = true;});
}

解决方案

< blockquote>

两件事。


首先,改变行的可见性而不是处理DataSource总是需要更长的时间,但行数不多不应该花费很多时间使用DataSource的大量行对于平均
的数据集来说会非常快,你没有表明你要处理多少行。


第二件事,通常一个过滤器不应该开始,直到至少有三到五个字符,许多专业图书馆都这样做。


Hello,

I am having datagridview with one string column and around 1 lackh rows where Datasource is null, I want to filter datagridview based on textbox text change event but it is taking time to filter and my form turns into not responding state.

string Temp = textBox2.Text.Trim();
            if (Temp != string.Empty)
            {
                this.dataGridView1.Rows.OfType<DataGridViewRow>().Where(r => !r.Cells[0].Value.ToString().ToUpper().Contains(Temp) && !r.Cells[0].Value.ToString().ToLower().Contains(Temp)).ToList().ForEach(row => { if (!row.IsNewRow) row.Visible = false; });
            }
            else
            {
                this.dataGridView1.Rows.OfType<DataGridViewRow>().ToList().ForEach(row => { if (!row.IsNewRow) row.Visible = true; });
            }

解决方案

Two things.

First, changing the visibility of rows rather than working off a DataSource is always going to take longer but with not many rows should not take much time yet with a large amount of rows will while using a DataSource will be extemely fast for an average set of data where you have not indicated how many rows you are dealing with.

Second thing, typically a filter should not start until there are at least three to five characters which many professional libraries do.


这篇关于过滤Datagridview没有数据源有1个缺乏行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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