Quantcast
Channel: Windows Desktop Development for Accessibility and Automation forum
Viewing all articles
Browse latest Browse all 585

C# - Compare listboxes - remove listbox item from listbox1 if it does not exist in listbox2

$
0
0

I'm trying to use the below but it's spitting out an error and won't work.

The error I'm receiving is:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll

Additional information: List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.

           

            foreach (string i in listbox1.Items)
            {
                if (!listbox2.Items.Contains(i))
                {
                    listbox1.Items.Remove(i);
                }
            }

Any help would be greatly appreciated.

Thanks


Viewing all articles
Browse latest Browse all 585

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>