I’m trying to remove objects from a BindingList that is bound to a DataGridView by doing this…
private void RemoveItems(List<Payment> removeList)
{
for (int i = removeList.Count - 1; i >= 0; i--)
{
sortableBindingPaymentList.Remove(removeList[i]);
}
}
Trying to debug this myself i attempted the following, however remover always = -1 (meaning that no match was found) and I’m 110% sure that my list of Payment’s in removeList contains a match in my sortableBindingList…
private void RemoveItems(List<Payment> removeList)
{
int remover;
for (int i = removeList.Count - 1; i >= 0; i--)
{
remover = sortableBindingPaymentList.IndexOf(removerList[i]);
sortableBindingPaymentList.RemoveAt(remover);
}
}
Any help is appreciated and thanks in advance!
I’m not sure I would go the
IEquatableway.. depending on the ORM you’re using that might bring you some trouble.Do your entities have a primary key? you can try this instead:
P.S: I strongly suggest you to start using LinQ for these kind of operations instead of
forloops.