Removing items from an arraylist

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have an 2 arraylist that contains a number of strings
What i want to do is to remove the items from arraylist1 if they exist in arraylist2. Can anyone help me do this?
I currently have code that removes items from a combobox based on an arraylists values(which was kindly provided by Cor). And so i jus need to modify this slightly...

While reader3.Rea
'place an array here of all the caravan invs availbl
Arraylist1.Add(reader3.GetSqlString(0)

For i = 0 To Arraylist2.Count -
'remove the inventory numbers that are in the array of previously booked cara'
Dim i As Intege
Dim AllBookedI As Integer = Combobox1.FindStringExact(Trim(Arraylist2(i))
'If we find it y is the index of the combobox row else it is -
If AllBookedI <> -1 The
CBoxCaraInv.Items.RemoveAt(AllBookedI
End I
Nex

Any help would be appreciated
 
Hi Bhavna,

If I remember me it well you did fill your combobox1 from that arraylist1.

And therefore should where you have this statement

CBoxCaraInv.Items.RemoveAt(AllBookedI)
arraylist1.removeAt(AllBookedI)

do the job for you.

Because the index should be the same.

Cor
 
Hi Bhavna,

Only add this row, I thought that should do it.

For i = 0 To Arraylist2.Count - 1
'remove the inventory numbers that are in the array of previously
booked cara's
Dim i As Integer
Dim AllBookedI As Integer =
Combobox1.FindStringExact(Trim(Arraylist2(i)))
'If we find it y is the index of the combobox row else it is -1
If AllBookedI <> -1 Then
CBoxCaraInv.Items.RemoveAt(AllBookedI)
--------------------------------
arraylist1.removeAt(AllBookedI)
----------------------------------
End If
Next

Tell me if it works and if not also?

Cor
 
Hi Cor

I cannot compare the arraylist to the values in the combobox because the combobox is no longer used in my application

That is why i cannot use the lin
Combobox1.FindStringExact(Trim(Arraylist2(i))

It is for this reason i need to compare the two arraylists together
Is there a way i could do this??
 
Hi Bhavna,

I make it for you but as I said before this is terrible code
\\\
dim i as integer
For i = 0 To ArrayList2.Count - 1
Dim y As Integer
for y = 0 to arraylist1.count - 1
if arraylist1(y).tostring = araylist2(i).tostring then
arraylist1.removeat(y)
exit for
end if
next
Next
////

I hope it works?

Cor
 
Back
Top