I use a ListView to show a list of items. When a new item is added, or the user moves one up or down (via buttons), I want the list to scroll to show/keep the item visible to the user. How can I do this?
Most articles I've found point to the ScrollIntoView() method or give complex code solutions. E.g. this question and answer uses ScrollIntoView() in WPF, but that isn't available for a ListView in Windows.Forms.
Use
ListView.EnsureVisible(index), which takes the index of the item you want to be visible. This will scroll the given item into view.Another option is to use
ListView.TopItem = itemToShow, but this will put it at the top of the list every time, whereasEnsureVisible()will scroll an item that is below the view up to the bottom position, which gives a clearer visual effect in your situation.