How to change scroll position in ListView

Hi guys, today I will show you how scroll bar can be programmatically manipulated using ListView in WPF.

Imagine that you have ListView that looks like this:


To change scroll position you can use ScrollIntoView method of ListView:

private void btnScroll_Click(object sender, RoutedEventArgs e) { int itemIndex = int.Parse(txtScrollItem.Text); object item = listView.Items[itemIndex]; listView.ScrollIntoView(item); }

As you can see this method takes object that is bound to any item in the list. In our case it is ListViewItem instance.

So in case you need to change scroll position programmatically you can use method described above Winking smile.