当前位置 : 主页 > 编程语言 > c语言 >

c# – 无法设置datagridview的行可见false

来源:互联网 收集:自由互联 发布时间:2021-06-25
我有一个DataGridView,我在其中设置DataSource: taskerEntities te = new taskerEntities();var OMsMasterDescriptiveIndicators = te.MyTable.Select(x = new lccls {Id = x.Id, name = x.name }).ToList();MyGrid.DataSource = OMsMasterDescri
我有一个DataGridView,我在其中设置DataSource:

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

和我的班级lccls一样

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

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

MyGrid.Rows[5].Visible = false;

但我无法做到这一点.而是抛出异常,并显示以下错误消息:

Row associated with the currency manager’s position cannot be made
invisible

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

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

CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[MyGrid.DataSource];  
currencyManager1.SuspendBinding();
MyGrid.Rows[5].Visible = false;
currencyManager1.ResumeBinding();
网友评论