加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 01:21:50 所属栏目:百科 来源:网络整理
导读:我有一个DataGridView,我在其中设置DataSource: taskerEntities te = new taskerEntities();var OMsMasterDescriptiveIndicators = te.MyTable.Select(x = new lccls {Id = x.Id,name = x.name }).ToList();MyGrid.DataSource = OMsMasterDescriptiveIndica
我有一个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();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读