P
Phill W.
(VB'2003)
What's the correct way to remove multiple, selected items from a
ListView control (say, from a ContextMenu)?
I ask because I'm getting a very annoying ArgumentOutOfRangeException
because the ListView seems to be trying to "re-select" items that are no
longer there!
for example, giventhat I have 3 items in my list:
Select the first and remove it - no problem.
Select the last /but one/ and remove it - still no problem.
Select the /last/ item and remove it - Boom!
ArgumentOutOfRangeException
Parameter name: '2' is not a valid value for 'displayIndex'
at S.W.F.ListViewItemCollection.getItem(Int32 displayIndex)
at S.W.F.ListView.LvnBeginDrag(MouseButtons buttons, NMLISTVIEW mnlv)
...
It's as if the "list" of select indices is being re-applied, even though
the items to which those items correspond[ed] have been removed.
Any suggestions?
What's the correct way to remove multiple, selected items from a
ListView control (say, from a ContextMenu)?
I ask because I'm getting a very annoying ArgumentOutOfRangeException
because the ListView seems to be trying to "re-select" items that are no
longer there!
for example, giventhat I have 3 items in my list:
Select the first and remove it - no problem.
Select the last /but one/ and remove it - still no problem.
Select the /last/ item and remove it - Boom!
ArgumentOutOfRangeException
Parameter name: '2' is not a valid value for 'displayIndex'
at S.W.F.ListViewItemCollection.getItem(Int32 displayIndex)
at S.W.F.ListView.LvnBeginDrag(MouseButtons buttons, NMLISTVIEW mnlv)
...
It's as if the "list" of select indices is being re-applied, even though
the items to which those items correspond[ed] have been removed.
Any suggestions?
Code:
Dim iIndices As Integer()
ReDim iIndices(Me.lvMembers.SelectedIndices.Count - 1)
Me.lvMembers.SelectedIndices.CopyTo(iIndices, 0)
For iIndex As Integer = iIndices.Length - 1 To 0 Step -1
Dim oItem As ListViewItem _
= Me.lvMembers.Items(iIndices(iIndex))
oItem.Selected = False ' even tried this!
Me.lvMembers.Items.Remove(oItem)
Next
TIA,
Phill W.