Aw, bugger..
It's confirmed, I have found my first legit bug :)
Reported : Jan 25, 2004
Confirmed: Jan 28, 2004
Error : ArgumentOutOfRangeException
Control : Listview Control
Framework: <= .NET Framework v1.1
Languages: All (Managed)
How to re-create:
- Add a Listview control to a form, and populate it with a few items.
- Add an handler for the SelectedIndexChanged event(default event when double clicked in VSIDE).
- In the event, show a modal dialog, then delete an item from the listview.
Private Sub listview1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listview1.SelectedIndexChanged
Dim lvItem As ListViewItem = listview1.SelectedItems(0)
'
'Comment out the msgbox line, then re-run and everything will be fine. If you leave in the msgbox, the code will fail on the remove statment, thus the bug. 'MsgBox("Test")
'<- Comment me ' 'Remove selected item 'lvItem.Remove()
End SubWork-around:
Use the Click event instead.
Microsofts reply:
"I have confirmed that what you reported is a bug with the ListView control. The problem is that when you call a MessageBox (or displaying a modal dialog) before removing the item from the ListView’s Items collection, the ListView incorrectly interprets that it has received a BeginDrag notification. It will try to drag the item which was already removed from the Items collection. But since the item is no longer there, it throws the ArgumentOutOfRangeException."