L
LarryMac
Here's my dilemma. I have a listbox that the user can select an item
("OrderItem" class) from, provided it hasn't already been selected (in
which case it will appear on a second list box). The following
procedure checks list2 (passed as lstSearch). It works fine the first
time through, but if the user attempts to add a second item, the
function crashes - throwing an Invalid castException on the indicated
line, saying that "Cast from type 'OrderItem' to type 'String' is not
valid."...despite the fact that it will work fine the first time
through!
Private Function OnList(ByVal strSearch As String, ByVal lstSearch As
ListBox) As Boolean
'Declare variables
Dim blnFound As Boolean
Dim intListIndex As Integer = 0
Do Until blnFound Or intListIndex = lstSearch.Items.Count
*If strSearch = CStr(lstSearch.Items(intListIndex)) Then*
blnFound = True
End If
intListIndex += 1
Loop
Return blnFound
End Function
Any thoughts?
("OrderItem" class) from, provided it hasn't already been selected (in
which case it will appear on a second list box). The following
procedure checks list2 (passed as lstSearch). It works fine the first
time through, but if the user attempts to add a second item, the
function crashes - throwing an Invalid castException on the indicated
line, saying that "Cast from type 'OrderItem' to type 'String' is not
valid."...despite the fact that it will work fine the first time
through!
Private Function OnList(ByVal strSearch As String, ByVal lstSearch As
ListBox) As Boolean
'Declare variables
Dim blnFound As Boolean
Dim intListIndex As Integer = 0
Do Until blnFound Or intListIndex = lstSearch.Items.Count
*If strSearch = CStr(lstSearch.Items(intListIndex)) Then*
blnFound = True
End If
intListIndex += 1
Loop
Return blnFound
End Function
Any thoughts?