繁体   English   中英

从排序列表中删除所选项后,选择下一项

[英]Select next item after removing selected item from sorted list

我有一个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?

您可以使用SelectedIndex 所以试试;

int i = ListView.SelectedIndex;
CountryData.Remove(item);
ListView.SelectedIndex = i;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM