快速的方法来制作的DataGridViewRow的不可见 [英] Faster Method to Making DataGridViewRow's non-Visible

查看:174
本文介绍了快速的方法来制作的DataGridViewRow的不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的代码来设置一堆的DataGridViewRow 元素是无形的。我使用的规则是检查相关的数据源的布尔标志。如果标志为true,则该行会显示出来。如果不是,这将是不可见的

I'm using the following code to set a bunch of DataGridViewRow elements to be invisible. The rule I am using is to check the associated datasource for a boolean flag. If the flag is true, the row will be displayed. If not, it will be invisible.

下面的代码工作;然而,通过消耗相当多的时间这样做:

The following code works; however, it does so by consuming quite a bit of time:

CurrencyManager currencyManager = (CurrencyManager)BindingContext[dataGridView.DataSource];

currencyManager.SuspendBinding();

foreach (DataGridViewRow row in dataGridView.Rows)
{
    if (!objectList.list[row.Index].Selected)
    {
        row.Visible = false;
    }
}
currencyManager.ResumeBinding();



有没有人有一个更好的解决方案?时间越长我不得不通过对象的列表中,搜索过程越长,自然。我不能设置一个单元格区域,因为布尔值可能不是连续的。

Does anyone have a better solution? The longer the list of objects I have to go through, the longer this process takes, naturally. I cannot set a range of cells because the boolean values may not be contiguous.

推荐答案

由于PraVn曾说过,你可以简单地过滤之前使用datagridview的。如果您在使用DataSet,DataTable中,或数据视图只是做了这一点:

As PraVn had said, you could simply filter prior to using the datagridview. If you are using a DataSet, DataTable, or DataView just do the this:

DataSet ds = new DataSet();
ds.Tables[0].DefaultView.RowFilter = "YourBooleanColumn = 1";

DataView dv = new DataView();
dv.RowFilter = "YourBooleanColumn = 1";

DataTable dt = new DataTable();
dt.RowFilter.DefaultView.RowFilter = "YourBooleanColumn = 1";



另外,你可以可以在数据库端过滤(如果有一个?)。让我们知道您的数据源是什么,我会适当的更新。这是我能做到最好!

Alternatively, you can could filter at the database end (if there is one?). Let us know what your data source is and I'll update as appropriate. This is the best I can do!

这篇关于快速的方法来制作的DataGridViewRow的不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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