Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

SelectedItems removal?

Last post 07-15-2008 12:20 by k3n51mm. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-11-2008 16:33

    • k3n51mm
    • Not Ranked
    • Joined on 07-07-2008
    • Points 185

    SelectedItems removal?

     Using WinListViews, we enable the user to multi-select items from a left-hand list view, and associate them with an item in the right-hand list view. Once a left-hand item is associated, it must be removed from the listview to prevent being associated to more than one right-hand item at a time.

    All is well until we try to remove the previously-associated items. We have also tried iterating in reverse through the SelectedItems collection using a counter variable. We tried this even though we had not received an enumeration error; we just tried whatever we could think of. The code below works in Microsoft's Listview control, so we can't figure why it fails here. Help?

     For Each ulvItem As UltraListViewItem In ulvLeft.SelectedItems
                    ulvLeft.Items.Remove(ulvItem)
    Next ulvItem

    • Post Points: 5
  • 07-11-2008 16:58 In reply to

    • k3n51mm
    • Not Ranked
    • Joined on 07-07-2008
    • Points 185

    Re: SelectedItems removal?

     Here is our current workaround in bold:

     

    For i As Integer = 0 To ulvLeft.SelectedItems.Count * 2

     For Each ulvItem As UltraListViewItem In ulvLeft.SelectedItems
                    ulvLeft.Items.Remove(ulvItem)
    Next ulvItem 

     Next i

    It seems as though if we back up and keep iterating through the collection, we will eventually get all of them removed.

    For three items, it took two passes; for five items, it took three passes. We think this may be something related to an earlier post concerning only the first and last SelectedItems being displayed. We'll keep this kludge in place until we hear a better way to do it.

    • Post Points: 20
  • 07-14-2008 9:40 In reply to

    Re: SelectedItems removal?

    This is a commonly made mistake; when you forward iterate the control's SelectedItems collection and remove items from the Items collection, you are decrementing the count of the SelectedItems collection, which causes every other item to be skipped. You have to reverse iterate instead:

    Dim i as Integer
    For i = uvLeft.SelectedItems.Count - 1 to 0 Step -1
        uvLeft.Items.Remove( uvLeft.SelectedItems(i) ) 
    Next

    • Post Points: 20
  • 07-15-2008 12:20 In reply to

    • k3n51mm
    • Not Ranked
    • Joined on 07-07-2008
    • Points 185

    Re: SelectedItems removal?

    Sorry, I hate being stupid. The Infragistics componenet does not throw the standard MS error when changing an enum while iterating, so I missed it.

    We're still working heavily with the listview right now, and have another question concerning disabling checkboxes.

     We used a solution we found (somewhere) on the Net to disable checkboxes in the WinListview. I noticed you answered another question concerning this issue and posted a solution, which we could not convert to VB.Net. Please see the new response to that quetsion, if you will.

    THX

     

    • Post Points: 5
Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems