我有一个DataGridView设置的位置DataSource:
DataGridView
DataSource
taskerEntities te = new taskerEntities(); var OMsMasterDescriptiveIndicators = te.MyTable.Select(x => new lccls {Id = x.Id, name = x.name }).ToList(); MyGrid.DataSource = OMsMasterDescriptiveIndicators;
与我class lccls一样
class lccls
public class lccls { public string Id { get; set; } public Nullable<decimal> name { get; set; } }
在某些情况下,我想使当前行不可见:
MyGrid.Rows[5].Visible = false;
但是我做不到。而是引发异常并显示以下错误消息:
与货币经理的头寸相关的行不能不可见
我怀疑原因与设置有关DataSource,但是为什么呢?
经过大量搜索,我找到了解决方案
CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[MyGrid.DataSource]; currencyManager1.SuspendBinding(); MyGrid.Rows[5].Visible = false; currencyManager1.ResumeBinding();