|
-
Nov 21st, 2004, 10:30 AM
#1
Thread Starter
New Member
-
Nov 21st, 2004, 11:25 AM
#2
Member
VB Code:
Dim i As Integer
For i = lstRedBlue.ListCount To 0 Step -1 'This means this will check each item in the box. The -1 is due to that the listbox adds 1 extra row.
If chkRed.Value = 1 And lstRedBlue.List(i) = "Red" Then
lstRedBlue.RemoveItem (i) 'If Red is checked then remove that row.
End If
If chkBlue.Value = 1 And lstRedBlue.List(i) = "Blue" Then
lstRedBlue.RemoveItem (i)
End If
Next i
[B]Updated
Last edited by Forge; Nov 21st, 2004 at 12:32 PM.
-
Nov 21st, 2004, 11:50 AM
#3
when removing multiple items from a listbox you should loop the listbox in reverse.
VB Code:
Dim i As Integer
For i = List1.ListCount - 1 To 0 Step -1
If List1.List(i) = Check1.Caption Then
If Check1.Value = vbChecked Then
List1.RemoveItem i
End If
ElseIf List1.List(i) = Check2.Caption Then
If Check2.Value = vbChecked Then
List1.RemoveItem i
End If
End If
Next i
casey.
-
Nov 21st, 2004, 11:57 AM
#4
Member
Both our codes work, but chose which you find easiest to understand.
-
Nov 21st, 2004, 12:04 PM
#5
Forge, that is not correct because of 2 reasons.
1. what if both checkboxes are ticked ?
2. if two items are the same and next to each other in a listbox then only one will get removed because the loop isnt going in reverse.
casey.
-
Nov 21st, 2004, 12:30 PM
#6
Thread Starter
New Member
EDIT: just me being a dummie, thanks for the help guys and gals
kellie
Last edited by kellievb; Nov 21st, 2004 at 12:35 PM.
-
Nov 21st, 2004, 12:45 PM
#7
Member
-
Nov 21st, 2004, 03:14 PM
#8
Originally posted by kellievb
EDIT: just me being a dummie, thanks for the help guys and gals
kellie
If your question is answered then please help everyone out by editing the first post and adding the green checkmark. Thanks.
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
|