DataGrid - grid selection is reset when new Data is arrived

后端 未结 3 884
囚心锁ツ
囚心锁ツ 2021-01-25 00:29

I have such DataGrid



        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-25 00:56

    In case the new dataSource still contains your last selected item and if you are following MVVM pattern. All you need to do is Raise PropertyChanged event for your selecetdItem once data source is reloaded. Make sure your viemModel implements INotifyPropertyChanged interface.

    EDIT

    And in case you don't want to clear your datasource every now and then. Simply, use the ObservableCollection in place of the generic list. It internally implements INotifyCollectionChanged, so any addition or deletion of item in your collection will be reflected on your UI.

提交回复
热议问题