You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
AdvancedCollectionView ArgumentOutOfRangeException when remove the last element #4263
When I use an AdvancedCollectionView and remove the last element from the bound collection the following exception thrown: 'System.ArgumentOutOfRangeException' in System.Private.CoreLib.dll Index was out of range. Must be non - negative and less than the size of the collection.
So, I think the issue here is DataGrid is trying to retrieve the item to know which one is removed, but it's already been removed from the collection when the event is called. Normally with an INotifyCollectionChanged event the item is provided in the event args, but that doesn't seem to be the case with the IVectorChangedEventArgs
If we swap the DataGrid for a ListView, things work fine. This seems to work fine in Wpf as they use the collectionchangedevent compared to an observablevector. FYI @RBrid.
Activity
michael-hawker commentedon Sep 21, 2021
Think this is a duplicate of #2913, thanks for providing a minimal repro project @Dimigergo.
Stack:
get:
WindowsCommunityToolkit/Microsoft.Toolkit.Uwp.UI/AdvancedCollectionView/AdvancedCollectionView.cs
Lines 212 to 216 in 760ab9f
removeAt:
WindowsCommunityToolkit/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGridDataConnection.cs
Lines 952 to 958 in 760ab9f
OnVectorChanged:
WindowsCommunityToolkit/Microsoft.Toolkit.Uwp.UI/AdvancedCollectionView/AdvancedCollectionView.Events.cs
Lines 55 to 66 in 760ab9f
WindowsCommunityToolkit/Microsoft.Toolkit.Uwp.UI/AdvancedCollectionView/AdvancedCollectionView.cs
Lines 627 to 639 in 760ab9f
WindowsCommunityToolkit/Microsoft.Toolkit.Uwp.UI/AdvancedCollectionView/AdvancedCollectionView.cs
Lines 741 to 751 in 760ab9f
So, I think the issue here is
DataGridis trying to retrieve the item to know which one is removed, but it's already been removed from the collection when the event is called. Normally with anINotifyCollectionChangedevent the item is provided in the event args, but that doesn't seem to be the case with theIVectorChangedEventArgsIf we swap the
DataGridfor aListView, things work fine. This seems to work fine in Wpf as they use the collectionchangedevent compared to an observablevector. FYI @RBrid.Mirofire commentedon Apr 15, 2023
Is this issue still open? I getting the same issue with Nuget package CommunityToolkit.WinUI.UI.Controls Version: 7.1.2
DavidM29 commentedon Apr 3, 2025
This has been open for 3.5 years, is the PR ever going to be merged?