【问题标题】:Deleting from a subsonic collection bound to a winforms datagridview从绑定到 winforms datagridview 的亚音速集合中删除
【发布时间】:2010-10-26 15:18:19
【问题描述】:
我有一个 winforms 应用程序,我通过 BindingSource 添加了一个绑定到亚音速集合的 DataGridView。
网格很好用于添加/编辑(display of the ComboBox column 除外),但我无法让它从数据库中正确删除行。
如果我从 DataGridView 中删除一行,我无法确定集合是否脏以及何时调用。亚音速集合的 BatchSave 方法,它会删除所有行。
【问题讨论】:
标签:
data-binding
collections
datagridview
subsonic
【解决方案1】:
在 2.2 版本中,SaveAll 还应该删除您从 datagridview 中删除的项目。
在 2.1 中你必须调用
ItemCollection.ProcessDeletedItems()
太
【解决方案2】:
这样做:
private void productBindingSource_ListChanged(object sender, ListChangedEventArgs e)
{
((ProductCollection)productBindingSource.List).SaveAll();
}