ICancelAddNew 接口


在向集合添加新项时添加事务性功能。Adds transactional capability when adding a new item to a collection.

public interface class ICancelAddNew
public interface ICancelAddNew
type ICancelAddNew = interface
Public Interface ICancelAddNew


使用 ICancelAddNew 接口,集合可以通过可扩展的方式添加新项。The ICancelAddNew interface enables a collection to add a new item in an extensible way. 然后,可以提交或回滚新项。The new item subsequently can be committed or rolled back. 集合的 AddNew 方法用于暂时添加项,后者随后将通过以下操作进行处理:The AddNew method of the collection is used to tentatively add the item, which is subsequently transacted through the following operations:

  • EndNew 方法将显式提交挂起的添加。The EndNew method will explicitly commit the pending addition.

  • 执行其他集合操作(如插入、删除或移动)将隐式提交挂起的添加操作。Performing another collection operation, such as an insertion, removal, or move will implicitly commit the pending addition.

  • 如果尚未提交挂起的添加,则 CancelNew 方法将回滚挂起的添加。The CancelNew method will roll back the pending addition if it has not already been committed.


在某些情况下(例如 Windows 窗体复杂的数据绑定),集合可能会收到新添加项之外的项的 CancelNewEndNew 调用。In some scenarios, such as Windows Forms complex data binding, the collection may receive CancelNew or EndNew calls for items other than the newly added item. (每个项通常是数据视图中的一行。)忽略这些调用;仅当指定了该项的索引时才取消或提交新项。(Each item is typically a row in a data view.) Ignore these calls; cancel or commit the new item only when that item's index is specified.

有两种模型允许将项事务性添加到数据绑定集合:There are two models that allow transactional addition of an item to a data-bound collection:



丢弃集合中挂起的新项。Discards a pending new item from the collection.


向集合提交挂起的新项。Commits a pending new item to the collection.