I have a program where I am trying to move items from one arraylist to another via a listbox but when I try to add it to the the second arraylist it does not add there.
ArrayList list1 = new ArrayList();
ArrayList list2 = new ArrayList();
list1.Add(new Class(var1, var2, var3, var4, var5, var6, var7));
foreach (object o in list1)
{
class m = (class)o;
selectionBox.Items.Add(m);
}
I initialised everything above and added everything to the class and then to the listbox. Note the vars I have got from an XML file.
bool req = true;
if (selectionBox.SelectedItem != null)
{
Count++;
errorLabel.Text = "";
for (int i = 0; i < selectionBox.Items.Count; i++)
{
if (selectionBox.GetSelected(i) == true)
{
class m = selectionBox.SelectedItem as class;
if (m.var2 == ((Modules)selectionBox.Items[i]).var2)
{
list2.Add(list1.IndexOf(i));
}
}
}
}
else
{
errorLabel.Text = "Error";
}
Here I am trying to add it to the second array list but it does not work the if statement however is correct I have tried this with print statements. So can someone tell me why the following line does not add to the list?
list2.Add(list1.IndexOf(i));
Countvariable?