Results 1 to 12 of 12

Thread: ***---Remove Listbox Items---***

  1. #1

    Thread Starter
    Lively Member mykg4orce's Avatar
    Join Date
    Oct 2000
    Location
    CANADA
    Posts
    92

    Exclamation

    if i have a number of items in a list box lets say a 100 and i want to remove 50 from the middle so 25 to 75. So how can i delete those items fromt he listbox. Al of this would be in a command button

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Code:
    For x=75 to 25 Step -1
      List1.RemoveItem x
    Next
    try that...
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Lively Member mykg4orce's Avatar
    Join Date
    Oct 2000
    Location
    CANADA
    Posts
    92
    no nothing seems to happen when i do this...what could be wrong

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    did you put it in the Command button's Click Event?
    try this
    Code:
    Private Sub Command1_Click()
      x = 1
      Do Until x=50
        List1.RemoveItem 25
        x = x + 1
      Loop
    End Sub
    Don't have VB in front of me, so I can't test it...
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    How bout this:
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Dim x As Integer
        For x = 75 To 25 Step -1
            List1.RemoveItem x
        Next
    End Sub
    
    Private Sub Form_Load()
        Dim x As Integer
        For x = 1 To 100
            List1.AddItem x
        Next
    End Sub

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Hey look at that...

    Just like my first code...
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  7. #7
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    hehehe...I know, just had to post exactly what to add to a form since you put in your floating, orphaned code. J/k......

  8. #8
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    good point...
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  9. #9

    Thread Starter
    Lively Member mykg4orce's Avatar
    Join Date
    Oct 2000
    Location
    CANADA
    Posts
    92
    thanks for the help guys!!!!!!!!

  10. #10
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    No problem..., couldn't have done it without crypt

  11. #11
    Addicted Member matbrophy's Avatar
    Join Date
    Sep 1999
    Location
    Kent, United Kingdom
    Posts
    149

    Arrow

    Just a simple little question, you can remove list items by listindex, but not by its text - unless you search for the text using a simple for...next loop.

    Any other way?

    Matthew

    Visual Basic 6.0 Professional
    Windows ME & Windows 2000 Professional

  12. #12
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You can use the listindex property, but an item has to be selected or you will invoke an error.

    Code:
    Private Sub Command1_Click()
        List1.RemoveItem List1.ListIndex
    End Sub

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