Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ private void NotifyingDataSource_VectorChanged(IObservableVector<object> sender,
{
// If we're grouping then we handle this through the CollectionViewGroup notifications.
// Remove is a single item operation.
_owner.RemoveRowAt(index, sender[index]);
_owner.RemoveRowAt(index);
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,12 @@ internal void RefreshRows(bool recycleRows, bool clearRows)
}
}

internal void RemoveRowAt(int rowIndex)
{
object item = GetRow(rowIndex)?.DataContext;
RemoveElementAt(SlotFromRowIndex(rowIndex), item, true);
}

internal void RemoveRowAt(int rowIndex, object item)
{
RemoveElementAt(SlotFromRowIndex(rowIndex), item, true);
Expand Down Expand Up @@ -1375,6 +1381,18 @@ private void EnsureRowDetailsVisibility(
raiseNotification);
}

private DataGridRow GetRow(int index)
{
if (_rowsPresenter != null)
{
return _rowsPresenter.Children[index] as DataGridRow;
}
else
{
return null;
}
}

private IEnumerable<DataGridRow> GetAllRows()
{
if (_rowsPresenter != null)
Expand Down
22 changes: 22 additions & 0 deletions UnitTests/UnitTests.UWP/UI/Test_AdvancedCollectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.Toolkit.Uwp.UI;
using Microsoft.Toolkit.Uwp.UI.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;

Expand Down Expand Up @@ -1053,6 +1054,27 @@ public void Test_AdvancedCollectionView_Sorting_CustomComparable_With_Shaping()
Assert.AreEqual(42, ((Person)a.First()).Age);
}

[TestCategory("AdvancedCollectionView")]
[UITestMethod]
public void Test_AdvancedCollectionView_Using_with_DataGrid()
{
var l = new ObservableCollection<string>
{
"lorem",
"ipsum",
"dolor",
"sit",
"amet"
};

var a = new AdvancedCollectionView { Source = l };
new DataGrid { ItemsSource = a };
Assert.AreEqual(5, a.Count);

l.RemoveAt(l.Count - 1);
Assert.AreEqual(4, a.Count);
}

private class DelegateComparable : IComparer
{
private Func<object, object, int> _func;
Expand Down
4 changes: 4 additions & 0 deletions UnitTests/UnitTests.UWP/UnitTests.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@
<Project>{d4ff799d-0df2-495a-adc9-3bbc4aef8971}</Project>
<Name>Microsoft.Toolkit.Uwp.UI.Behaviors</Name>
</ProjectReference>
<ProjectReference Include="..\..\Microsoft.Toolkit.Uwp.UI.Controls.DataGrid\Microsoft.Toolkit.Uwp.UI.Controls.DataGrid.csproj">
<Project>{DAEB9CEC-C817-33B2-74B2-BC379380DB72}</Project>
<Name>Microsoft.Toolkit.Uwp.UI.Controls.DataGrid</Name>
</ProjectReference>
<ProjectReference Include="..\..\Microsoft.Toolkit.Uwp.UI.Controls.Layout\Microsoft.Toolkit.Uwp.UI.Controls.Layout.csproj">
<Project>{cb444381-18ba-4a51-bb32-3a498bcc1e99}</Project>
<Name>Microsoft.Toolkit.Uwp.UI.Controls.Layout</Name>
Expand Down