i'm trying to compare 2 listview items to check for duplicates
one listview is in a form and the other one is in a different open form
i get this error :
System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.'
how to solve this error please
invoicesnew master = (invoicesnew)Application.OpenForms["invoicesnew"];
if (master.radListView1.Items.Count == 0)
{
foreach (ListViewDataItem a1234 in radListView1.Items)
{
ListViewDataItem item = new ListViewDataItem();
item.SubItems.Add(a1234["Column 0"].ToString());
item.SubItems.Add(a1234["Column 1"].ToString());
item.SubItems.Add(a1234["Column 2"].ToString());
item.SubItems.Add(a1234["Column 3"].ToString());
item.SubItems.Add(a1234["Column 4"].ToString());
item.SubItems.Add(a1234["Column 5"].ToString());
item.SubItems.Add(a1234["Column 6"].ToString());
item.SubItems.Add(a1234["Column 7"].ToString());
master.radListView1.Items.Add(item);
this.Close();
}
}
else
{
foreach (ListViewDataItem item in radListView1.Items)
{
foreach (ListViewDataItem a1234 in master.radListView1.Items)
{
if (item["Column 0"].ToString() == a1234["Column 0"].ToString() && item["Column 1"].ToString() == a1234["Column 1"].ToString())
{
master.radListView1.FilterDescriptors.Clear();
master.radListView1.FilterDescriptors.LogicalOperator = FilterLogicalOperator.Or;
master.radListView1.FilterDescriptors.Add("Column 0", FilterOperator.Contains, item["Column 0"].ToString());
master.radListView1.FilterDescriptors.Add("Column 1", FilterOperator.Contains, item["Column 1"].ToString());
master.radListView1.EnableFiltering = true;
master.radListView1.SelectedIndex = 0;
decimal totalin = Convert.ToDecimal(item["Column 7"].ToString());
decimal countin = Convert.ToDecimal(item["Column 5"].ToString());
decimal totalin1 = Convert.ToDecimal(a1234["Column 7"].ToString());
decimal countin1 = Convert.ToDecimal(a1234["Column 5"].ToString());
alltotal = (totalin1 + totalin).ToString();
allcount = (countin1 + countin).ToString();
List<
ListViewDataItem
> saveSelectedItems = new List<
ListViewDataItem
>();
foreach (ListViewDataItem eachItem in master.radListView1.SelectedItems)
{
saveSelectedItems.Add(eachItem);
}
foreach (ListViewDataItem item3 in saveSelectedItems)
{
master.radListView1.Items.Remove(item3);
}
ListViewDataItem item1 = new ListViewDataItem();
item1.SubItems.Add(item["Column 0"].ToString());
item1.SubItems.Add(item["Column 1"].ToString());
item1.SubItems.Add(item["Column 2"].ToString());
item1.SubItems.Add(item["Column 3"].ToString());
item1.SubItems.Add(item["Column 4"].ToString());
item1.SubItems.Add(allcount);
item1.SubItems.Add(price);
item1.SubItems.Add(alltotal);
master.radListView1.Items.Add(item1);
}
else
{
master.radListView1.EnableFiltering = false;
calculate();
ListViewDataItem item1 = new ListViewDataItem();
item1.SubItems.Add(radLabel13.Text);
item1.SubItems.Add(radLabel29.Text);
item1.SubItems.Add(radLabel15.Text);
item1.SubItems.Add(radDropDownList3.Text);
item1.SubItems.Add(radLabel24.Text);
item1.SubItems.Add(radMaskedEditBox3.Text);
item1.SubItems.Add(price);
item1.SubItems.Add(total);
master.radListView1.Items.Add(item1);
this.Close();
}
}
}
}