ListView Control

S

Scott Toney

I have a list view that I am populating from a database. I am doing some
manipulation on the data and then I want the listview to "refresh", so I am
trying to remove the items / subitems in the list box with:
If (lvChief.Items.Count > 0) Then
For Index = 1 To lvChief.Items.Count

lvChief.Items.Remove(lvChief.Items.Item(0))

Next

End If

I created a button to do lvChief.Items.Remove(lvChief.Items.Item(0)), the
number of times that corresponds to the number of entries in my listview, it
removes them, but when I use the above steps, I get an:

System.ArgumentOutOfRangeException:index

Thanks

Scott
 
D

Daniel Moth

1. Iterating a collection and removing from it at the same time is not
generally advisable

2. When iterating the listview (or any other type from the Collections
namespace), change the "Index = 1" to start at 0 instead

3. Why not use the Items.Clear method?

Cheers
Daniel
 
S

Scott Toney

I appreciate all of the suggestions, I changed to lvChief.Items.clear and I
get a:
System.ArgumentOutOfRangeException:index
 
D

Daniel Moth

Are you handling the SelectedIndexChanged event (or any others) from the
listview? If yes, show us the code (you should be checking in there that
there actually selected items before accessing any items).

Cheers
Daniel
 
S

Scott Toney

Thanks a bunch, that is it.

Daniel Moth said:
Are you handling the SelectedIndexChanged event (or any others) from the
listview? If yes, show us the code (you should be checking in there that
there actually selected items before accessing any items).

Cheers
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Listview on .net CF 2.0 0
No items displayed in Listview 4
ListView problems 3
Listview Control 1
Row Color for ListView 1
ListView Hang? 1
Using Listview CF 2.0 1
Prevent ellipses in listview item 0

Top