views:

27

answers:

1

I have a ListView that gets updated frequently, at irregular intervals.

I want it so that when an update is received the item will be scrolled into view.

I know the code to do that:

logListView.ScrollIntoView(logListView.Items[logListView.Items.Count - 1]);

I don't know where to put it so that it happens when the ListView is updated.

I've tried putting it in the LayoutUpdated event handler of the ListView, but when I try to scroll during a period when there are no updates (I know there aren't any updates because I've turned the message pump off) the view is stuck at the bottom. I'm guessing this is because scrolling raises a LayoutUpdated event.

How do I get the ListView to scroll to the bottom when it receives a new item?

+2  A: 

Take a look at the answer to WPF ListBox Scroll when item added. The Items property is an ItemCollection, which implements INotifyCollectionChanged, so you can use the CollectionChanged event. It should work for a ListView as well as a ListBox, but if you're using ScrollIntoView then I suspect you have a ListBox anyway.

INotifyCollectionChanged collection = logListView.Items;
collection.CollectionChanged += collection_CollectionChanged;
Quartermeister
I can confirm that I have a ListView. This does work for ListView. Thanks for you answer it's just what I needed.
Matt Ellen