|
-
Mar 29th, 2007, 02:04 AM
#1
Thread Starter
Junior Member
Help with removing post from a ListBox (VB6)
Hi,
I have a project in VB6 where I have a ListBox (lstCombo). I wish to be able to add and remove 4-char long combinations in this ListBox.
I have a CommandButton (cmdAdd) that looks like this:
----------------------------------------
'Add a combination to the list.
Private Sub cmdAdd_Click()
Dim strToAdd As String
strToAdd = InputBox("Combination to include: ", "Enter Combination")
If Len(Trim$(strToAdd)) > 0 Then
If Not ListItemExists(strToAdd) Then
lstCombo.AddItem strToAdd
End If
End If
End Sub
----------------------------------------
I also have a CommandButton (cmdRemove) that I will be able to remove posts with, but I does not manage to get this to work. My (not so good) try looked like this:
----------------------------------------
'Remove a combination from the list.
Private Sub cmdRemove_Click()
Dim strToRemove As String
strToRemove = InputBox("Combination to remove: ", "Enter Combination")
If Len(Trim$(strToRemove)) > 0 Then
If ListItemExists(strToRemove) Then
lstCombo.RemoveItem strToRemove
End If
End If
End Sub
----------------------------------------
Can you maybe instead do so you click and mark one post and then click “remove”?
I Would also like to have a CommandButton (cmdRemoveAll) that completely clears the ListBox.
If anyone has any good ideas on how to solve this in a good way, I would be very thankful!
/M
Last edited by mats_1; Mar 29th, 2007 at 02:32 AM.
-
Mar 29th, 2007, 02:13 AM
#2
Re: Help with removing post from a ListBox (VB6)
In oder to remove a listitem you need the .ListIndex of this item.
I guess you could get this information using your Fuction "ListItemExists", which you didn't post, so I'm assuming from here on!
Right now the Function just gives True or False, in case in gives True it must have loop in some way to the .ListIndex that has the searched Value. Just use a global Var and store this Listindex there for later use.
your codeline :"stCombo.RemoveIntem strToRemove" should then be changed to "stCombo.RemoveIntem intSavedListIndex" (with intSavedListIndex beeing to saved ListIndex from your Function).
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Mar 29th, 2007, 02:20 AM
#3
Re: Help with removing post from a ListBox (VB6)
On the second question:
vb Code:
Private Sub cmdRemoveAll()
Dim i as Integer
For i=0 to UBound (lstCombo.ListCount-1)
lstCombo.RemoveItem i
Next i
End Sub
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Mar 29th, 2007, 02:41 AM
#4
Re: Help with removing post from a ListBox (VB6)
 Originally Posted by opus
On the second question:
vb Code:
Private Sub cmdRemoveAll()
Dim i as Integer
For i=0 to UBound (lstCombo.ListCount-1)
lstCombo.RemoveItem i
Next i
End Sub
Or lstCombo.Clear?
-
Mar 29th, 2007, 04:16 AM
#5
Thread Starter
Junior Member
Re: Help with removing post from a ListBox (VB6)
Thank you for your help, i will try this!
I now understand that AddItem and RemoveItem does not work entirely the same way
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
|