【发布时间】:2013-06-01 18:53:38
【问题描述】:
我在 WPF 中使用 ItemSource 以及所有使 UI 刷新它的类和事件创建了一个 ListBox。但是我的Remove方法有问题:
Public Sub Remove(ItemIndex As Integer)
MyList.RemoveAt(ItemIndex)
RaiseEvent CollectionChanged(Me, New NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, MyList(ItemIndex)))
End Sub
但是当我执行此操作时,我收到一条消息,指出索引(在本例中为 ItemIndex)超出范围。但在输出窗口中它显示索引为“0”(否则它将从MyList 中删除该项目)。
【问题讨论】:
-
好吧,如果列表中没有项目,索引
0(索引第一个项目)将超出范围。 -
为什么需要以编程方式引发事件?
标签: vb.net indexing range out inotifycollectionchanged