无法将 datagridview 的行可见设置为 false

2023-12-11

我有一个DataGridView我设置的地方DataSource:

taskerEntities te = new taskerEntities();
var OMsMasterDescriptiveIndicators = te.MyTable.Select(x => new lccls {Id = x.Id, name = x.name }).ToList();
MyGrid.DataSource = OMsMasterDescriptiveIndicators;

with my class lccls as

public class lccls
    {
        public string Id { get; set; }
        public Nullable<decimal> name { get; set; }
    }

在某个事件中,我想让当前行不可见:

 MyGrid.Rows[5].Visible = false;

但我无法做到这一点。相反,会引发异常并显示以下错误消息:

无法创建与货币经理职位关联的行 无形的

我怀疑原因与设置有关DataSource, 但为什么?


经过大量搜索后,我得到了solution

CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[MyGrid.DataSource];  
currencyManager1.SuspendBinding();
MyGrid.Rows[5].Visible = false;
currencyManager1.ResumeBinding();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法将 datagridview 的行可见设置为 false 的相关文章

随机推荐