我能够获得添加到 BindingList 的项目的索引。当我尝试获取索引时,如果已删除的项目出现错误
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
这是我的代码
Private Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemove.Click
For i As Integer = 0 To _assignedSelection.SelectedCount - 1
Dim item As Jurisdiction = CType(_assignedSelection.GetSelectedRow(i), Jurisdiction)
_list.Remove(item)
Next
End Sub
Private Sub list_Change(ByVal sender As Object, ByVal e As ListChangedEventArgs) Handles _list.ListChanged
If (_list.Count > 0) Then
Select Case e.ListChangedType
Case ListChangedType.ItemAdded
_dal.InsertJurisdiction(_list.Item(e.NewIndex))
Case ListChangedType.ItemDeleted
'MsgBox(e.NewIndex.ToString)
_dal.DeleteJurisdiction(_list.Item(e.NewIndex)) <--------HERE
End Select
End If
End Sub
编辑:也欢迎 C# 中的答案....有人吗?