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
Printable View
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
try that...Code:For x=75 to 25 Step -1
List1.RemoveItem x
Next
no nothing seems to happen when i do this...what could be wrong
did you put it in the Command button's Click Event?
try this
Don't have VB in front of me, so I can't test it...Code:Private Sub Command1_Click()
x = 1
Do Until x=50
List1.RemoveItem 25
x = x + 1
Loop
End Sub
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
Just like my first code...:D
hehehe...I know, just had to post exactly what to add to a form since you put in your floating, orphaned code. J/k......:D
good point...:cool:
thanks for the help guys!!!!!!!!
No problem...:), couldn't have done it without crypt
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
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