【问题标题】:Change a BindingSource items, silently默默地更改一个 BindingSource 项
【发布时间】:2013-11-05 11:03:15
【问题描述】:

[更新]

我有一个包含一些对象列表的BindingSource 对象(一个BindingList<T> 用作BindingSource 的源,<T> 实现了INotifyPropertyChanged),有没有办法插入或删除一些对象到BindingSource,务实地说,这不会导致引发ListChanged 事件?

例如: 当我写这段代码时:

myBindingSource.Insert(5,someObject);

我不想引发ListChanged 事件。

【问题讨论】:

  • 我们需要更多信息,你在使用 Observablecollections 吗?
  • @Alexandre:不,我使用 BindingList 作为 BindingSource 的来源
  • 你能给我们一些代码吗?
  • 您可以通过标记 event.Handled = true 来捕捉事件并防止其冒泡。也就是说,我会重新审视逻辑,看看我是否可以完全避免这种情况。
  • @Tomtom 我更新了帖子。

标签: c# winforms events binding bindingsource


【解决方案1】:

您可以设置RaiseListChangedEvents 属性以允许或不允许引发事件ListChanged

myBindingSource.RaiseListChangedEvents = false;
myBindingSource.Insert(5,someObject);
myBindingSource.RaiseListChangedEvents = true;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 2020-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多