Solved

VB 2005 Delete all rows selected in a ListView

Posted on 2007-11-19
9
750 Views
Last Modified: 2013-11-26
Hi

In Visual Studio 2005 VB, how would you delete all the rows selected in a ListView where multiselect is true
0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 20317888
For Each item as ListViewItem in somelistview.SelectedItems
      somelistview.Remove(item)
Next
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20317896
I think should be instead:

For Each item as ListViewItem in somelistview.SelectedItems
      somelistview.Items.Remove(item)
Next
0
 

Author Comment

by:murbro
ID: 20317897
Hi

Looking around the net I found this example, posted by angelII, which is better?
If you want to remove the items from the list, change the loop, because for each will fail if you remove items:

dim l as long
for l = ListView.ListItems.Count - 1 to 0
  if ListView.Listitems(l).Selected then
    ListView.Listitems.Remove l
  end if
next
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:murbro
ID: 20317929
Just tested both. You were right. Thanks very much and sorry about the confusion
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20317934
You can do it this way, to avoid fail:

Dim items as Array = new Array(somelistview.SelectedItems.Count)
somelistview.SelectedItems.CopyTo(items,0)
For Each item as ListViewItem in items
      somelistview.Items.Remove(item)
Next
0
 

Author Comment

by:murbro
ID: 20317939
Thanks very much
0
 

Author Comment

by:murbro
ID: 20317947
I am getting an error on the "New Array" saying
" 'New' cannot be used on a class that is declared 'mustinherit' "
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20317971
Sorry, C# customs. Try with:

Dim items(somelistview.SelectedItems.Count-1) As Object
0
 

Author Comment

by:murbro
ID: 20318044
Great. That worked. Thanks very much!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

742 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question