bs.RemoveCurrent();
在所有其他时间都可以使用。 My only hint for a solution is to remove all bindings and reapply them but this doesn't seem like an ideal solution.
eDit
仅在BindingList成功地删除所讨论的最后一项之后,该异常才会被抛弃。它被扔进了外部代码,所以我无法确切地分辨出什么是扔它。,我在这里,请问一些帮助:)。提前感谢 Justin
Here is how I remove selected row from a grid:
private void btnDelete_Click(object sender, EventArgs e)
{
if (grid.CurrentRow == null) return;
var selectedItem = grid.CurrentRow.DataBoundItem as PartGroup;
if (selectedItem != null &&
UIHelper.ShowQuestion("Are you sure you want to delete selected row?") == System.Windows.Forms.DialogResult.Yes)
{
groups.Remove(selectedItem);
}
}
groups is my BindingListEx(Of T).
希望它有帮助
[对不起,这不是一个真正的答案,但我觉得这很有价值,因为没有给出任何答案。 使用.NET Compact Framework 2.0,我的情况完全相同。 测试将其追溯到使用NumericUpdown.databindings.add()将控件绑定到源的点。 此后,如果该项目是源中的最后一个,则使用removeCurrent()将产生错误。 在绑定之前(或跳过),错误将永远不会出现。 其他控件与此相同的源绑定 - 文本框和Combobox - 但它们并未引起这种行为。 仅数字控制控制。
我怀疑根本原因与crurnermanager.findgoodrow在一起。如果在空列表上调用该方法(基于源代码onhttps://www.dotnetframework.org/),此方法将引发无效的操作异常。该方法是由ibindinglist触发的。listchanged,可能是其他时间。
这也可以解决范围异常以外的dataGridView索引。
IBindingList data = /* the BindingList */;
data.ListChanged += ListChanged;
bindingSource.DataSource = data;
bindingSource.Position = 0;
void ListChanged(Object? sender, ListChangedEventArgs e)
{
if (e.ListChangedType is ListChangedType.ItemDeleted &&
data.Count is 0)
{ bindingSource.RaiseListChangedEvents = false;}
}