VB.NET索引';0';超出范围了吗?

VB.NET索引';0';超出范围了吗?,vb.net,indexing,range,out,inotifycollectionchanged,Vb.net,Indexing,Range,Out,Inotifycollectionchanged,我在WPF中创建了一个列表框,其中包含一个ItemSource,以及所有使UI刷新它的类和事件。但是我的Remove方法有一个问题: 公共子删除(ItemIndex为整数) MyList.RemoveAt(ItemIndex) RaiseEvent CollectionChanged(Me,新建NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove,MyList(ItemIndex)) 末端接头 但是,当我执行此

我在WPF中创建了一个列表框,其中包含一个
ItemSource
,以及所有使UI刷新它的类和事件。但是我的
Remove
方法有一个问题:

公共子删除(ItemIndex为整数)
MyList.RemoveAt(ItemIndex)
RaiseEvent CollectionChanged(Me,新建NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove,MyList(ItemIndex))
末端接头


但是,当我执行此操作时,会收到一条消息,表明索引(在本例中为
ItemIndex
)超出范围。但在输出窗口中,它表示索引为“0”(否则它将从
MyList
中删除该项)。

问题已解决!我改了密码

公共子删除(ItemIndex为整数)
MyList.RemoveAt(ItemIndex)
RaiseEvent CollectionChanged(Me,新建NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove,MyList(ItemIndex))
末端接头

进入

公共子删除(ItemIndex为整数)
RaiseEvent CollectionChanged(Me、New NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove、MyList(ItemIndex)、ItemIndex))
MyList.RemoveAt(ItemIndex)
末端接头


仅此而已。

如果列表中没有项目,索引
0
(第一个项目的索引)将超出范围。为什么需要以编程方式引发事件?