0

I have this collection:

ObservableCollection<MyData> Files;

This collection is full of objects and i put this list inside my ListView:

ItemsSource="{Binding Files}"

Now when my application do the work vai Parallel.Foreach (via different threads) i want to be able to cange the order inside my ListView. I have try something like that:

private void MoveItem()
{
    var itemToMove = lvPcapFiles.Items[3];
    lvPcapFiles.Items.RemoveAt(0);
    lvPcapFiles.Items.Insert(0, itemToMove);
}

And when try to use it i have this InvalidOperationException error:

Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.

mark yer
  • 403
  • 6
  • 12
  • 1
    The exception message clearly says what to do: sort the `Files` collection instead of `lvPcapFiles.Items`. Otherwise you may use a `SortDescription` in conjuction with a `CollectionViewSource`. – Clemens Oct 12 '15 at 10:11
  • If i move item from 1 place to another inside my collection it reflect my ListView ? – mark yer Oct 12 '15 at 10:16
  • Sure, that's why you have an ObservableCollection. – Clemens Oct 12 '15 at 10:43

0 Answers0