InvalidArgument=Value of '8' is not valid for 'index'.
There is no 9th item in your list
@(you need an account to see links)
(you need an account to see links)
I dont get why that doesnt work.
Its for a kad feeder. Never really worked in c# before. lsttemp is a list containing both the ids and item names. And lstignore is the items to ignore.
I believe the problem is when it deletes the last thing in the list.
^Thats the error I get.Code:InvalidArgument=Value of '8' is not valid for 'index'.
And this line is highlighted:
Code:if (lsttemp.Items[i].ToString().Contains(removelistitem))
Last edited by Josh; 12-11-2012 at 01:27 AM.
InvalidArgument=Value of '8' is not valid for 'index'.
There is no 9th item in your list
(you need an account to see links)
(you need an account to see links)(you need an account to see links)
------------------------
[02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
------------------------
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.
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(); int index = lsttemp.FindString(removelistitem); if (index >= 0) { lsttemp.Items.RemoveAt(index); } }
Hope that helps.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); } } }
That works perfect. Thanks for the help.
You should probably use a custom class (ie Item.cs) for storing Item Names with corresponding IDs.
I like my way.
Lol @(you need an account to see links) knows his shit
(you need an account to see links)
(you need an account to see links)(you need an account to see links)
------------------------
[02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
------------------------
Zachafer (12-27-2012)