0

I made a ListBox in WPF with an ItemSource and with all those classes and events that make the UI refresh it. But there's a problem in my Remove method:

Public Sub Remove(ItemIndex As Integer)
MyList.RemoveAt(ItemIndex)
RaiseEvent CollectionChanged(Me, New NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, MyList(ItemIndex)))
End Sub

But when I execute this I get a message that the index (in this case ItemIndex) is out of range. But in the output window it says that the index is '0' (otherwise it would remove the item from MyList).

Jan Böhm
  • 89
  • 1
  • 11

1 Answers1

0

Problem solved! I changed the code

Public Sub Remove(ItemIndex As Integer)
MyList.RemoveAt(ItemIndex)
RaiseEvent CollectionChanged(Me, New NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, MyList(ItemIndex)))
End Sub

into

Public Sub Remove(ItemIndex As Integer)
RaiseEvent CollectionChanged(Me, New NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, MyList(ItemIndex), ItemIndex))
MyList.RemoveAt(ItemIndex)
End Sub

That's all.

Jan Böhm
  • 89
  • 1
  • 11