Yes, this is pretty annoying, but there is an easy workaround. I create a class BindingListBase<T>that I use for all my lists instead of the usual one BindingList<T>. Since my class inherits from BindingList<T>, I have access to all its protected members, including the method RemovedItem.
This allows me to choose when the item will be deleted. You can do what I do and have a list of mRemovedItems to which I always add items, or create my own “ItemRemoved” event.
See my sample code below:
Public MustInherit Class BindingListBase(Of T)
Inherits BindingList(Of T)
Protected mRemovedItems As New List(Of T)
Protected Overrides Sub ClearItems()
MyBase.ClearItems()
mRemovedItems.Clear()
End Sub
Protected Overrides Sub RemoveItem(ByVal index As Integer)
Dim item As T = MyBase.Item(index)
MyBase.RemoveItem(index)
mRemovedItems.Add(item)
End Sub
Public ReadOnly Property RemovedItems as List(Of T)
Get
Return mRemovedItems
End Get
End Property
End Class
source
share