I am trying to remove numerical items from a ListBox if those values exist in another ListBox. My code does not seem to work and I could not locate any help online. ListBox1 is populated by Array and ListBox2 is populated from a DataSet table (fyi).
Also for reference: I'm not adding and items to a listbox or selecting...simply just want to compare both and remove ListBox2 items from ListBox1 if they exist all automatically with a press of a button. Thank you,
private void button1_Click(object sender, EventArgs e)
{
foreach (int item in listBox1.Items)
{
if (listBox2.Items.Contains(item))
{
listBox1.Items.Remove(item);
}
}
}
foreach (int item in listBox1.Items)
trylistBox2.Items
. – Yuriiif
statement to explicitly check fortrue
– rommel