Nutshell: How can I disable the auto-scroll back to the top of a ListBox when I call RemoveAt(0)?
Background:
I have a simple list box that I mash full of data at regular intervals.
Basically I’m using it is a status reporting tool.
Every iteration of my program causes 100 or so lines of data to be thrown into the listbox and the best way to dump piles of information in is by always adding it to the bottom.
I want newest results to be at the bottom, and the oldest results to be “pushed up”. Because the size of this listbox becomes rather large after a short period of time I limit the size to 1000 items.
When the box gets more than 1000 items, I use RemoveAt(0) till I get 1000 items again.
To always display the most relevant information I scroll the listbox all the way down. The problem with this is that whenever I call RemoveAt(0), the box is auto-scrolled back up to the new item 0. Basically, every time I add items to a “full” list box, the effect is a quick scroll up 1000 items, then back down 1000 items, making for a clumsy looking display.
How can I disable the auto-scroll back to the top of a ListBox when I call RemoveAt(0)?
This will only happen when there is no selected item. Or in other words, ListBox.SelectedIndex = -1. The simple workaround is to select an item. Like the last one.