473,728 Members | 1,712 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 10083
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
3114
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
8652
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
3484
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
4878
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
6801
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
4032
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
7339
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
1709
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
2841
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
9411
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9265
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...
0
9122
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
8113
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...
1
6704
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6012
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2159
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.