ListCollectionView移至新创建的记录 [英] ListCollectionView moving to newly created record
问题描述
使用ListCollectionView时,如何将焦点移至新创建的记录? 我的声明是
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)
我尝试使用MyView.MoveCurrentTo(Dunno放在这里),但似乎没有任何作用.
I've tried using MyView.MoveCurrentTo(Dunno what to put here) but nothing seems to work.
如果我正在使用基础的ObservableCollection,那么我将转到索引0,但是我不能依靠它,因为可以对ListCollectionView进行排序和过滤,因此记录不再与ObservableCollection相同./p>
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 .
推荐答案
您尝试过吗?
MyView.MoveCurrentTo(MyView.CurrentAddItem)
您还可以使用MyView.AddNew添加新项目,我怀疑它已成为当前项目.
You could also use MyView.AddNew to add the new item, I suspect it makes it the current item.
此外,不要忘记在ItemsControl上将IsSynchronizedWithCurrentItem设置为True
Also, don't forget to set IsSynchronizedWithCurrentItem to True on your ItemsControl
这篇关于ListCollectionView移至新创建的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!