473,883 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing multiple items from a multi-select ListView

(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 ArgumentOutOfRa ngeException
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!

ArgumentOutOfRa ngeException
Parameter name: '2' is not a valid value for 'displayIndex'
at S.W.F.ListViewI temCollection.g etItem(Int32 displayIndex)
at S.W.F.ListView. LvnBeginDrag(Mo useButtons 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.lvM embers.Selected Indices.Count - 1)
Me.lvMembers.Se lectedIndices.C opyTo(iIndices, 0)

For iIndex As Integer = iIndices.Length - 1 To 0 Step -1
Dim oItem As ListViewItem _
= Me.lvMembers.It ems(iIndices(iI ndex))

oItem.Selected = False ' even tried this!
Me.lvMembers.It ems.Remove(oIte m)
Next

TIA,
Phill W.
Jul 27 '06 #1
5 10096
Why do you select the item to remove it
Get the index of the item you want to remove and use the
ListView.Items. RemoveAt method

hth,
Samuel

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:ea******** **@south.jnrs.j a.net...
(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 ArgumentOutOfRa ngeException
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!

ArgumentOutOfRa ngeException
Parameter name: '2' is not a valid value for 'displayIndex'
at S.W.F.ListViewI temCollection.g etItem(Int32 displayIndex)
at S.W.F.ListView. LvnBeginDrag(Mo useButtons 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.lvM embers.Selected Indices.Count - 1)
Me.lvMembers.Se lectedIndices.C opyTo(iIndices, 0)

For iIndex As Integer = iIndices.Length - 1 To 0 Step -1
Dim oItem As ListViewItem _
= Me.lvMembers.It ems(iIndices(iI ndex))

oItem.Selected = False ' even tried this!
Me.lvMembers.It ems.Remove(oIte m)
Next

TIA,
Phill W.

Jul 27 '06 #2
Samuel,
Why do you select the item to remove it
I don't - I'm trying to "un-select" it in the vain hope that the
ListView control won't then try to redisplay it in a "selected" way (or
/any/ way, come to that), which is what's causing it to blow up.
Get the index of the item you want to remove and use the
ListView.Items. RemoveAt method
Yep - tried that. Same results using Remove(item) and RemoveAt(index) .

Regards,
Phill W.

Samuel Shulman wrote:
Why do you select the item to remove it
Get the index of the item you want to remove and use the
ListView.Items. RemoveAt method

hth,
Samuel

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:ea******** **@south.jnrs.j a.net...
>(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 ArgumentOutOfRa ngeException
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!

ArgumentOutOfR angeException
Parameter name: '2' is not a valid value for 'displayIndex'
at S.W.F.ListViewI temCollection.g etItem(Int32 displayIndex)
at S.W.F.ListView. LvnBeginDrag(Mo useButtons 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.lvM embers.Selected Indices.Count - 1)
Me.lvMembers.S electedIndices. CopyTo(iIndices , 0)

For iIndex As Integer = iIndices.Length - 1 To 0 Step -1
Dim oItem As ListViewItem _
= Me.lvMembers.It ems(iIndices(iI ndex))

oItem.Selected = False ' even tried this!
Me.lvMembers.It ems.Remove(oIte m)
Next

TIA,
Phill W.

Jul 27 '06 #3
Phill W. wrote:
(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 ArgumentOutOfRa ngeException
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!

ArgumentOutOfRa ngeException
Parameter name: '2' is not a valid value for 'displayIndex'
at S.W.F.ListViewI temCollection.g etItem(Int32 displayIndex)
at S.W.F.ListView. LvnBeginDrag(Mo useButtons 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.lvM embers.Selected Indices.Count - 1)
Me.lvMembers.Se lectedIndices.C opyTo(iIndices, 0)

For iIndex As Integer = iIndices.Length - 1 To 0 Step -1
Dim oItem As ListViewItem _
= Me.lvMembers.It ems(iIndices(iI ndex))

oItem.Selected = False ' even tried this!
Me.lvMembers.It ems.Remove(oIte m)
Next

TIA,
Phill W.
At the risk of seeming to talk to myself (not a first, by any means) it
looks like the SelectedIndices might be a Red Herring.

I /only/ get this problem if the item corresponding to the last item I
selected (by Clicking and Ctrl-Clicking in the ListView) is removed, so...
If I select the last item in the list, then the first, I can remove them
both and the first item remains selected.
If I select the first item, then the last, and remove them - Boom!

Regards,
Phill W.
Jul 27 '06 #4
Maybe that,
When you actually remove an item then the index of the other items changes
and if say the maximum index value was 10 after removing any item it will be
9

You can do 1 of the following:
1. Record to some variables (array) a unique value of the items you want to
remove and find out the index of that item each time based on that value
then usse the removeAt

2. Reference all the items to remove to a created array of items then loop
through this array (I hope that the valuue of the index will change as you
go along)
hth,
Samuel Shulman

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:ea******** **@south.jnrs.j a.net...
Samuel,
Why do you select the item to remove it
I don't - I'm trying to "un-select" it in the vain hope that the ListView
control won't then try to redisplay it in a "selected" way (or /any/ way,
come to that), which is what's causing it to blow up.
Get the index of the item you want to remove and use the
ListView.Items. RemoveAt method

Yep - tried that. Same results using Remove(item) and RemoveAt(index) .

Regards,
Phill W.

Samuel Shulman wrote:
>Why do you select the item to remove it
Get the index of the item you want to remove and use the
ListView.Items .RemoveAt method

hth,
Samuel

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:ea******* ***@south.jnrs. ja.net...
>>(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 ArgumentOutOfRa ngeException
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!

ArgumentOutOf RangeException
Parameter name: '2' is not a valid value for 'displayIndex'
at S.W.F.ListViewI temCollection.g etItem(Int32 displayIndex)
at S.W.F.ListView. LvnBeginDrag(Mo useButtons 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.lvM embers.Selected Indices.Count - 1)
Me.lvMembers. SelectedIndices .CopyTo(iIndice s, 0)

For iIndex As Integer = iIndices.Length - 1 To 0 Step -1
Dim oItem As ListViewItem _
= Me.lvMembers.It ems(iIndices(iI ndex))

oItem.Selected = False ' even tried this!
Me.lvMembers.It ems.Remove(oIte m)
Next

TIA,
Phill W.
Jul 27 '06 #5
Samuel,

Found it!

Old habits die hard: I was displaying the Context Menu manually (using
ContextMenu.Sho w) but from the ListView's Mouse/Down/ event instead of
Mouse/Up/.

Moved my code into[ListView].MouseUp and everything works as expected!

Regards,
Phill W.

Samuel Shulman wrote:
Maybe that,
When you actually remove an item then the index of the other items changes
and if say the maximum index value was 10 after removing any item it will be
9

You can do 1 of the following:
1. Record to some variables (array) a unique value of the items you want to
remove and find out the index of that item each time based on that value
then usse the removeAt

2. Reference all the items to remove to a created array of items then loop
through this array (I hope that the valuue of the index will change as you
go along)
hth,
Samuel Shulman

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:ea******** **@south.jnrs.j a.net...
>Samuel,
>>Why do you select the item to remove it
I don't - I'm trying to "un-select" it in the vain hope that the ListView
control won't then try to redisplay it in a "selected" way (or /any/ way,
come to that), which is what's causing it to blow up.
>>Get the index of the item you want to remove and use the
ListView.Item s.RemoveAt method
Yep - tried that. Same results using Remove(item) and RemoveAt(index) .

Regards,
Phill W.

Samuel Shulman wrote:
>>Why do you select the item to remove it
Get the index of the item you want to remove and use the
ListView.Item s.RemoveAt method

hth,
Samuel

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:ea****** ****@south.jnrs .ja.net...
(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 ArgumentOutOfRa ngeException
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!

ArgumentOutO fRangeException
Parameter name: '2' is not a valid value for 'displayIndex'
at S.W.F.ListViewI temCollection.g etItem(Int32 displayIndex)
at S.W.F.ListView. LvnBeginDrag(Mo useButtons 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.lvM embers.Selected Indices.Count - 1)
Me.lvMembers .SelectedIndice s.CopyTo(iIndic es, 0)

For iIndex As Integer = iIndices.Length - 1 To 0 Step -1
Dim oItem As ListViewItem _
= Me.lvMembers.It ems(iIndices(iI ndex))

oItem.Selected = False ' even tried this!
Me.lvMembers.It ems.Remove(oIte m)
Next

TIA,
Phill W.
Jul 28 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3119
by: Jeremy Owens-Boggs | last post by:
We are trying to implement a dual list box selection where you have two list boxes, You highlight items in the right side list box, click a button and this moves those items over to the left hand list box. The problem is that if there are many items selected (thousands), then removing the items from the right side list box takes for ever because we are removing them one at a time, which causes the listbox to re-index everything before we...
2
8658
by: Chris | last post by:
I find tons of info on adding, but what about removing an item dynamically? I'm cycling through the list and removing users that have special rights. I've tried things like: ddcontactnames.Items.Remove(userdata("CONTACT_ID")) but how do I pick the value on the item and remove it? thanx.
3
3496
by: Arun | last post by:
Hi, I have simple question to ask. How to write multiple Binary files to the Browser using Asp.Net and Visual C#.net I have seen examples where single binary file is written to browser. -Regards Arun
2
4890
by: Milsnips | last post by:
hi there, i have the following HTML code: -------------------------- <asp:DropDownList id="hddList" runat="server"> <asp:ListItem Value="1">Item 1</asp:ListItem> <asp:ListItem Value="2">Item 2</asp:ListItem> <asp:ListItem Value="3">Item 3</asp:ListItem> <asp:ListItem Value="4">Item 4</asp:ListItem> <asp:ListItem Value="5">Item 5</asp:ListItem>
10
6810
by: Backwards | last post by:
Hello all, I'll start by explaining what my app does so not to confuss you when i ask my question. ☺ I have a VB.Net 2.0 app that starts a process (process.start ...) and passes a prameter through from a combo box. The combo box items are made up of IP address and computer host name. Anything a user places in this combo box it writes this to a txt file called history.txt
4
4036
neo008
by: neo008 | last post by:
Hi all, Finally gave up and putting it here. I am new to visual basic stucked up with an error- Run time errors.'-2147217887 (8004021)': Multiple-step operation generated errors. check each status value. Error comes at ADODC.RECORDSET.UPDATE command.
2
7346
by: beatTheDevil | last post by:
Hey guys, As the title says I'm trying to make a regular expression (regex/regexp) for use in removing the comments from code. In this case, this particular regex is meant to match /* ... */ comments. I'm using Ruby v.1.8.6 Here's my regex: multiline_comments = /\/\*(.*?)\*\// When I try myStr.gsub(multiline_comments, "")
1
1732
by: robinthezhu | last post by:
Hello, I recently ported my code to Tornado 2.2 VxWorks5.5 I finaly got all the projects to build and compile,but in the last stage of the build when I link the application software with the ppc BSP, I get an multiple definition to items associated with the Standard Template Libraries. this did not occur with 2.0. The errors are listed below, any help Please the multi-definition is: __default_alloc_template<true,...
7
2850
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds to support cloning: Public Class RefClass Public tcp As TcpClient Public name As String End Class Public Class RefClassList Inherits List(Of RefClass) Implements ICloneable
0
198
by: Scott David Daniels | last post by:
Here are some tweaks on both bits of code: Paul McGuire wrote: .... m = for b in bases: if hasattr(b, '__mro__'): if MetaHocObject.ho in b.__mro__: m.append(b) if m:
0
9936
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10412
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9571
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5797
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4610
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3231
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.