Windows Forms ListView runtime errors

0

I'm trying to manage data by transferring ListViewItem objects from different ListViews (All of them are created on runtime)

And I'm facing a number of odd errors. Running this loop:

foreach (ListViewItem item in items)
{
    this.view.Items.Add((ListViewItem)item.Clone());
}

gives me this error:

System.IndexOutOfRangeException occurred
  HResult=0x80131508
  Message=Index was outside the bounds of the array

And this code:

(Moving an item object from one list to another while ensuring other threads are not accessing the same lists)

while (this.backEnd.isUpdating && this.passive.isUpdating) ;
this.backEnd.isUpdating = true;
this.passive.isUpdating = true;
this.backEnd.Items[i].Remove();
this.passive.Items.Add(this.backEnd.Items[i]);
this.backEnd.isUpdating = false;
this.passive.isUpdating = false;

gives me this error:

System.ArgumentException occurred
  HResult=0x80070057
  Message=Cannot add or insert the item '54d' in more than one place. You must first remove it from its current location or clone it.
Parameter name: item

What could cause these issues and how can I fix them? Thank you

c#
winforms
visual-studio
asked on Stack Overflow Nov 10, 2017 by Joe Dock

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0