ListCollectionView moving to newly created record

社会主义新天地 提交于 2020-01-03 04:34:15

问题


When using a ListCollectionView, how do I move focus to the newly created record? My declarations are

Public WithEvents Data As PersonList = PersonList.GetList()
Private MyView As New ListCollectionView(Data)
Private WithEvents _Person As Person

The code I use to insert a person is

    _Person = New Person("AAAA", 100)
    Data.Insert(0, _Person)

I've tried using MyView.MoveCurrentTo(Dunno what to put here) but nothing seems to work.

If I was working with the underlying ObservableCollection then I would go to index 0, but I can't rely on this as the ListCollectionView can be sorted and filtered so the records are no longer in the same order as the ObservableCollection .


回答1:


Have you tried that ?

MyView.MoveCurrentTo(MyView.CurrentAddItem)

You could also use MyView.AddNew to add the new item, I suspect it makes it the current item.

Also, don't forget to set IsSynchronizedWithCurrentItem to True on your ItemsControl



来源:https://stackoverflow.com/questions/913644/listcollectionview-moving-to-newly-created-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!