Results 1 to 5 of 5

Thread: delete in collection and listbox(RESOLVED)

Threaded View

  1. #1

    Thread Starter
    Lively Member SunFlower_Queen's Avatar
    Join Date
    Nov 2004
    Posts
    101

    Resolved delete in collection and listbox(RESOLVED)

    This piece of code is used in a class module to delete an item form a collection of objects in that class. It also has to re-key the remaining items to match the indexes in a listbox so it always deletes the same item from the list and collection. It works for the first delete but then consistently deletes the item after the selected one. Can anyone see what is wrong with this code?

    VB Code:
    1. Public Sub DeleteControl(ByVal Index As Integer)
    2.     'delete item from collection
    3.     Me.FormControls.Remove CStr(Index)
    4.            
    5. '       change key for all collection items that are after deleted item
    6. '       remove item with key(index) and add it as key(index - 1)
    7.     For Index = Index To FormControls.Count - 1
    8.         Me.FormControls.Add FormControls(CStr(Index + 1)), CStr(Index)
    9.         Me.FormControls.Remove CStr(Index + 1)
    10.        
    11.     Next
    12. ENd sub
    Last edited by SunFlower_Queen; Dec 2nd, 2004 at 03:10 PM.
    ~*~*~*~*~*~*
    Sunflower Queen

    If you have knowledge, let others light their candles at it.
    -- Margaret Fuller

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width