Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ListView Control

67 views
Skip to first unread message

Scott Toney

unread,
Jul 26, 2005, 11:32:22 AM7/26/05
to
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


Daniel Moth

unread,
Jul 26, 2005, 11:43:43 AM7/26/05
to
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
--
http://www.danielmoth.com/Blog/


"Scott Toney" <sc...@spine-brain.com> wrote in message
news:11ecm25...@corp.supernews.com...

Peter Foot [MVP]

unread,
Jul 26, 2005, 11:46:06 AM7/26/05
to
Why not just call:-

lvChief.Items.Clear()

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net |
http://www.opennetcf.org

"Scott Toney" <sc...@spine-brain.com> wrote in message
news:11ecm25...@corp.supernews.com...

Chris Tacke, eMVP

unread,
Jul 26, 2005, 11:47:57 AM7/26/05
to
Why not just use lvChief.Items.Clear() ?


--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate


"Scott Toney" <sc...@spine-brain.com> wrote in message
news:11ecm25...@corp.supernews.com...

Scott Toney

unread,
Jul 26, 2005, 12:49:57 PM7/26/05
to
I appreciate all of the suggestions, I changed to lvChief.Items.clear and I
get a:
System.ArgumentOutOfRangeException:index

"Chris Tacke, eMVP" <cta...@spamfree-opennetcf.org> wrote in message
news:%23x0Zmlf...@TK2MSFTNGP09.phx.gbl...

Daniel Moth

unread,
Jul 26, 2005, 12:59:33 PM7/26/05
to
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).

"Scott Toney" <sc...@spine-brain.com> wrote in message

news:11ecqm7...@corp.supernews.com...

Scott Toney

unread,
Jul 26, 2005, 1:02:42 PM7/26/05
to
Thanks a bunch, that is it.

"Daniel Moth" <dmo...@hotmail.com> wrote in message
news:udDNyMgk...@tk2msftngp13.phx.gbl...

0 new messages