-
Ok, heres my problem.
I've got two listboxes. I've got a popup menu when I rightclick in each listbox. When I hit delete in the menu it doesnt delete the selected item in the listbox, but the item at the very top. Here's what i've got.
Code:
Private Sub mnuDEL2_Click()
Dim x As Variant
Dim xx As Variant
x = lstfilename.Selected
xx = lstURL.Selected
lstfilename.RemoveItem (x)
lstURL.RemoveItem (xx)
End Sub
I get an error "Argument Not Optional"
Any help is appreciated..
-
wow, my code was way off.. Thanks matt.
-
Private Sub mnuDEL2_Click()
Dim x As Variant
Dim xx As Variant
x = lstfilename.listindex
xx = lstURL.listindex
lstfilename.RemoveItem (x)
lstURL.RemoveItem (xx)
End Sub
-
I got it. Matthew Gates posted the answer. I guess he deleted it because it's gone.
but this is what i used.
Code:
lstfilename.RemoveItem (lstfilename.ListIndex)
lstURL.RemoveItem (lstURL.ListIndex)
-
I did delete it cuz I found something better.
Code:
On Error Resume Next
Dim i As Integer
With List1
For i = .ListCount - 1 To 0 Step -1
If .Selected(i) Then
.RemoveItem (i)
End If
Next
End With
At least...for multiple selection.
-
By the way, is that what you wanted? It did do the job. But it only removed 1 item.
Code:
lstfilename.RemoveItem (lstfilename.ListIndex)
lstURL.RemoveItem (lstURL.ListIndex)
Your welcome..if that is what you needed :rolleyes:.
-
Well I dont want to delete multi lines with that, but I used the code to delete multi items in another place in my project. so thanks again. :)
-
Well, I'm glad I was right..once again :rolleyes:.
I guess I was thinking ahead and you might've said that it wasn't the code you wanted. Reason I thought that was because the Selected property is for multiple select. ListIndex is for single selecting.
Glad it helped.