私は、ボタンのクリックイベントに次のコードを持って、両方のそのリストボックスや収集を確認し、同じポイントで開始します。(0または1)
If myCollection.Count > 0 Then
Dim curItemIndex As Integer = myListbox.SelectedIndex
If myCollection.Item(curItemIndex) IsNot Nothing Then
myCollection.Remove(curItemIndex)
MessageBox.Show("Address removed!")
Else
MessageBox.Show("Could not delete entry!")
End If
Else
MessageBox.Show("Address book is empty!")
End If
私はコレクションに項目を追加する場合、それを削除しよう、私はいつもこのエラーが出る:
System.IndexOutOfRangeException: 'Collection index must be in the range 1 to the size of the collection.'
私は、デバッガをステップ実行、私はこれを参照してください。
myCollection.Count = 1
SelectedIndexを= 0
curItemIndex = 0
それは、コレクションが1
から始まり言うとき、リストボックスで現在選択されている項目が0である理由だから私は得ることはありませんどうすれば両方とも0で始まるように修正できますか?
ありがとうございます!
'Collection'を使い続ければ' If myCollection.Item(curItemIndex + 1)IsNot Nothing Then'' myCollection.Remove(curItemIndex + 1) 'です。しかし、あなたは 'List'を使用してListViewをバインドする必要があります。 – djv