Removing Item From Listbox
Hello people,
I have a listbox that gets populated when a command button on the same form is clicked. When, the listbox gets populated, a listbox in another form is also getting populated at the same time.
The problem is that when I try to remove an item from a listbox, I have an error. I cannot remove the item from the listbox in another form.
These are the two codes that I tried.
VB Code:
Dim Nm123 As String
Nm123 = lstOrder.Text
Dim ABC As Single
ABC = -1
Dim Trial As String
Dim DEF As String
DEF = ABC + 1
For i = 1 To frmPizzaChoices.lstItems.ListCount
Trial = frmPizzaChoices.lstItems.List(DEF)
If Trial = lstOrder.Text Then
frmPizzaChoices.lstItems.RemoveItem (DEF)
End If
Next i
This is a simpler code
VB Code:
frmPizzaChoices.lstItems.RemoveItem (lstOrder.ListIndex)
Can someone please suggest a different way to display this.
Re: Removing Item From Listbox
VB Code:
Private Sub Command1_Click()
Dim i As Integer
With frmPizzaChoices
For i = 0 To .lstItems.ListCount - 1
If .lstItems.List(i) = lstOrder.Text Then
.lstItems.RemoveItem (i)
End If
Next i
End With
End Sub
Re: Removing Item From Listbox
Probably better to use ,
VB Code:
For i = .lstItems.ListCount - 1 To 0 Step -1
instead of ,
VB Code:
For i = 0 To .lstItems.ListCount - 1
Re: Removing Item From Listbox
With this code also, i have one problem, the item doesn't get removed for some reason.