Search code examples
wpflistcollectionview

ListCollectionView moving to newly created record


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 .


Solution

  • 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