I have a for loop that for each item in a listbox it will perform a sub. Whats weird is the for loop didnt iterate at all. I had to force it to iterate to the first item but after if finished performing all the subs for that item it just stopped.
How can I make it keep iterating for each item in the listbox?
Heres my code:
listBox7.SelectedIndex = 0;
for (int i = 0; i < listBox7.Items.Count; i++)
{
sub1();
sub2();
listBox1.Items.Add(listBox7.SelectedItem.ToString() + "\r");
while (listBox7.SelectedItems.Count > 0)
{
listBox7.Items.Remove(listBox7.SelectedItems[0]);
}
webBrowser1.Navigate("http://www.google.com");
}
You are most likely removing all of the items in the inner while statement, leaving nothing to iterate on in the second pass.
If your listBox1 contains more than 1 item, an exception will always be thrown on the following line:
because there is no longer a selected item.
This is why exception handling, even if you are just testing something, is critical.
If your goal is to process every item in listBox7, then you can accomplish this by moving the following line:
inside the for loop, above the line