从排序列表

时间:2016-10-13 10:01:52

标签: c# wpf

我有一个ListView,它由来自CollectionViewSource的排序数据填充,从ObservableCollection填充。像那样

<CollectionViewSource x:Key="cvsSortByName" Source="{Binding CountryData}">
    <CollectionViewSource.SortDescriptions>
        <scm:SortDescription PropertyName="Name"/>
    </CollectionViewSource.SortDescriptions>
</CollectionViewSource>

<ListView ItemsSource="{Binding Source={StaticResource cvsSortByName}}" SelectedItem="{Binding SelectedStuff}"/>

从ObservableCollection中删除项目时,如何选择排序列表中的下一个项目。例如,我们有以下内容:

index id  name
0     1   1
1     3   3
2     4   4

添加2

index id  name
0     1   1
3     5   2 - SelectedStuff 
1     3   3
2     4   4

从ObservableCollection

中删除3 5 2
CountryData.Remove(item);

如何制作1 3 3 SelectedStuff?

1 个答案:

答案 0 :(得分:0)

您可以使用SelectedIndex。所以试试;

int i = ListView.SelectedIndex;
CountryData.Remove(item);
ListView.SelectedIndex = i;
相关问题