Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding a Term in a LIST BOX and Deleting 1

Status
Not open for further replies.

PSUIVERSON

Technical User
Nov 6, 2002
95
US
I am attempting to use a variable and find it within a list box that has been populated already and then delete it based on the variable value.

All I found so far is

listBox.RemoveItem n

* The problem with this is that I want to remove the item based on the ListBox.text value AND not the INDEX Value.

So for example I would get the variable then I would attempt to search for that value in the entire list box set of values and DELETE It out.

How can I do this?

Thanks
 
try,

for i=0 to list1.listcount-1
if <strvariable> = list1.list(i) then
list1.removeitem i
end if
next i


Thanks and Good Luck!

zemp
 
You are the man...Worked like a charm...

' Team 1
Do While Not rst.EOF
If IsNull(rst!team1) = False Then
i = 0
lstTeam1.AddItem (rst!team1)
selectedPlayer(1) = rst!team1
playerPos(1) = Right(selectedPlayer(1), 2)
End If

Select Case playerPos(1)
Case &quot;QB&quot;
For i = 0 To lstQB.ListCount - 1
If selectedPlayer(1) = lstQB.List(i) Then
lstQB.RemoveItem i
GoTo nextTeam2
End If
Next i
Case &quot;RB&quot;
For i = 0 To lstRB.ListCount - 1
If selectedPlayer(1) = lstRB.List(i) Then
lstRB.RemoveItem i
GoTo nextTeam2
End If
Next i
Case &quot;WR&quot;
For i = 0 To lstWR.ListCount - 1
If selectedPlayer(1) = lstWR.List(i) Then
lstWR.RemoveItem i
GoTo nextTeam2
End If
Next i
Case &quot;TE&quot;
For i = 0 To lstTE.ListCount - 1
If selectedPlayer(1) = lstTE.List(i) Then
lstTE.RemoveItem i
GoTo nextTeam2
End If
Next i
Case &quot;K&quot;
For i = 0 To lstK.ListCount - 1
If selectedPlayer(1) = lstK.List(i) Then
lstK.RemoveItem i
GoTo nextTeam2
End If
Next i
Case &quot;D&quot;
For i = 0 To lstD.ListCount - 1
If selectedPlayer(1) = lstRB.List(i) Then
lstRB.RemoveItem i
GoTo nextTeam2
End If
Next i
End Select
 
How about this...its a quick way to find an item in a listbox with an api call.I am not sure how advanced you are, but i find this to be a good way to do it. The case doesnt matter for the searchstring.



Private Const LB_FINDSTRING = &H18F
Private Const LB_FINDSTRINGEXACT = &H1A2

Private Declare Function SendMessageString Lib &quot;user32&quot; _
Alias &quot;SendMessageA&quot; _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long

Private Sub Command1_Click()
Dim lngindex As Long
Dim strFind As String

strFind = &quot;FindThis&quot;

lngindex = SendMessageString(List1.hwnd, _
LB_FINDSTRINGEXACT, _
-1, _
strFind)

If lngindex > -1 Then
list1.removeitem lngindex
End If
End Sub



Just another way to do it...probably more work and more confusing...but why not post anyways.

Paul J.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top