The root of the problem is that your inner loop and outer loop should be reversed. Since you can possibly change the list items from the outer loop while you are still running the inner loop, removing the last item from the list will cause problems.
Here are two different solutions, the first one is simpler, the second reverses your loops so the code should work without error.
This first example takes advantage of ListBox.FindString which does an efficient search of the list and uses only a single for loop of the ignore list.
Code:
for (int b = lstignore.Items.Count - 1; b >= 0; --b) {
string removelistitem = lstignore.Items[b].ToString();
int index = lsttemp.FindString(removelistitem);
if (index >= 0) {
lsttemp.Items.RemoveAt(index);
}
}
The second example is similar to what you had but is fixed by swapping the two loops around so its safe to change the first list in the second loop.
Code:
for (int b = lstignore.Items.Count - 1; b >= 0; --b) {
string removelistitem = lstignore.Items[b].ToString();
for (int i = lsttemp.Items.Count - 1; i >= 0; --i) {
if (lsttemp.Items[i].ToString().Contains(removelistitem)) {
lsttemp.Items.RemoveAt(i);
}
}
}
Hope that helps.