|
-
Jan 7th, 2006, 05:14 PM
#1
Thread Starter
Hyperactive Member
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.
-
Jan 7th, 2006, 06:45 PM
#2
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
-
Jan 7th, 2006, 06:52 PM
#3
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
-
Jan 7th, 2006, 07:07 PM
#4
Thread Starter
Hyperactive Member
Re: Removing Item From Listbox
With this code also, i have one problem, the item doesn't get removed for some reason.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|