Results 1 to 4 of 4

Thread: EASY List box question. Answer soon...

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Karhula, Finland
    Posts
    4

    Post

    Im using listbox (style "Checked")[BR]
    How can I remove items from the list? I need to remove the checked items from the list.[BR]
    I have a command button in the form. What code do I need to enter to the command button so that it removes the selected item(s) from the list?[BR]
    Thank you!

  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    The easiest way may be to clear the list box and reenter the list with just those items.

    listbox.clear I believe will clear it.

    If you know the items, then just put em back in if they get loaded from something else then before clearing:
    dim strItems() as string, intI as integer
    dim intItems as integer

    intItems = listbox.listcount
    redim strItems(intItems)
    for inti = 1 to intItems
    stritems(inti) = listbox.ItemData(inti)
    next inti

    'now you have all the items, you could put if statement in the loop to skip certain items.
    dim intJ as integer
    redim strItems(intItems - number of items you are removing)
    intJ = 1
    for inti = 1 to intItems
    if listbox.itemdata(inti) <> "Cleared item" then
    stritems(intj) = listbox.ItemData(inti)
    intJ = intJ +1
    end if
    next inti

    Hope this helps.

  3. #3
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post


    Personally, I would do it this way:

    Code:
    Private Sub cmdRemoveSeletedItems_Click()
    Dim i As Integer
    
    
    For i = List1.listCount - 1 To 0 Step -1
      If List1.Selected(i) Then
        List1.RemoveItem (i)
      End If
    Next i
    End Sub
    ------------------
    Mark Sreeves
    Analyst Programmer

    Mark.Sreeves@Softlab.co.uk
    A BMW Group Company



  4. #4
    Lively Member
    Join Date
    Jan 2000
    Location
    Springfield, IL
    Posts
    124

    Post

    This code will check all your items in the list and remove only the ones that are selected.
    Code:
        Dim i As Integer
        Dim intMaxItems As Integer
        
        intMaxItems = List1.ListCount - 1
        i = 0
        Do While i <= intMaxItems
            MsgBox List1.List(i)
            If List1.Selected(i) = True Then
                List1.RemoveItem i
                intMaxItems = intMaxItems - 1
            Else
                i = i + 1
            End If
        Loop

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