Free 6 months hosting on Discount ASP
 
  Forum  Commercial Foru...  Commercial Foru...  Simple Updating Of ListView
Previous Previous
 
Next Next
New Post 5/27/2009 8:47 PM
  derekmhart@yahoo.com
531 posts
1st Level Poster


Simple Updating Of ListView 
Modified By derekmhart@yahoo.com  on 5/27/2009 10:57:41 PM)

I have a listview, showing checkboxes, and I want to clear the checked items. I think this is how I would do this in Winforms, but not sure. Do I need the Me.Update(), or should I do Me.myListView.Update() ? This is not working at all.

                For i As Integer = myListView.CheckedItems.Count - 1 To 0 Step -1
                    myListView.Items(i).Checked = False
                Next
                Me.Update()


 

 
New Post 5/27/2009 9:38 PM
  dubem1
777 posts
1st Level Poster




Re: Simple Updating Of ListView 
Modified By dubem1  on 5/27/2009 11:39:48 PM)

Your code is wrong

Imagine you have 10 items in your listview and items 9 and 10 are checked.

myListView.CheckedItems.Count will return 2 and then in your for ...next you try to uncheck item 0 and 1 which are not checked.

P.S. You should post your general question in the public forum How do I

Martin

 
New Post 5/27/2009 10:30 PM
  derekmhart@yahoo.com
531 posts
1st Level Poster


Re: Simple Updating Of ListView 

Well I know I can loop the whole listview, like this:

                For i As Integer = .Items.Count - 1 To 0 Step -1
                    .Items(i).Checked = False
                Next

But I was hoping to be able to just loop the checked items list.  Can that be done?

 
New Post 5/28/2009 3:24 PM
  palli
5908 posts
1st Level Poster




Re: Simple Updating Of ListView 

Hi Derek,

With a minor change your original code should work. Martin is right what your original code is not working. Your original code was:


               For i As Integer = myListView.CheckedItems.Count - 1 To 0 Step -1
                    myListView.Items(i).Checked = False
                Next

Your approach is correct to go from the last item to the first, but within the loop you don't access the correct item by going through a different collection. The "i" is an index into CheckedItems collection, and does say nothing about the index within the Items collection.

Two ways to fix... either is the CheckedItems collection within the loop, or get each item, get it's index and then use the Items collection to access it.

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 5/28/2009 6:10 PM
  derekmhart@yahoo.com
531 posts
1st Level Poster


Re: Simple Updating Of ListView 

My concern was with using CheckedIndices; many messages out there have stated it is unreliable. Well, it looks like it works. Any known problems of the reliability of CheckedIndices?

                For i As Integer = .CheckedItems.Count - 1 To 0 Step -1
                    .Items(.CheckedIndices(i)).Checked = False
                Next
 

 
Previous Previous
 
Next Next
  Forum  Commercial Foru...  Commercial Foru...  Simple Updating Of ListView
Most promising startups
Top 3 most promising startups in 2009
   AJAX Framework | Web Development | Cloud applications | RIA Development | Silverlight Applications | Legacy Migration
The most popular open source Ajax applications framework for enterprises | Sitemap | Terms Of Use | Privacy Statement
Copyright © 2005-2009 Visual WebGui®    Design By: Template World
   
Visual Studio Partners