I currently have a itemsCollection and a historyCollection. Both are separate isolated .dat files.
The saving and displaying works fine for both of these isolated storages, however the problem is when I try to delete something out of the itemCollection I also want to remove all the items out of the historyItemCollection where the historyItemCollection contains that specific itemIndex.
Update:
The itemCollection could contain something like this:
- a
- b
- c
The historyItemCollection could look like this:
- a
- b
- c
- b
So if I remove b (itemIndex 1) then I want both to be removed in the historyItemCollection.
I can remove the items out of the itemCollection fine, but the historyItemCollection throws errors.
int i = 0;
for (i = 0; i <= App.ViewModel.historyItemCollection.Count-1; i++)
{
if (App.ViewModel.historyItemCollection[i].VehicleId == (Application.Current as App).vehicleIndex)
{
App.ViewModel.historyItemCollection[i].Remove(i);
}
}
App.ViewModel.vehicleItemsCollection[(Application.Current as App).vehicleIndex].Remove((Application.Current as App).vehicleIndex);
The error message I’m getting:
Parameter name: index
It fails on this line:
App.ViewModel.historyItemCollection[i].Remove(i);
In this line do you really mean both of these to be
itemIndex?Also, does calling
RefreshItems()have any impact onitemIndex?I’d recommend breaking your code up into more lines – then single stepping through.
As an aside, why are you setting the DataContext in this method? Then why are you also setting it twice – and to different types of objects each time. This seems unusual – perhaps you could instead set the DataContext globally to a new ViewModel class which has the history and items as children?