This is a class I've found handy a couple of times when writing viewers for streaming data. In these cases, we want a collection that has the following unique behaviors:
- Items are added to the top of the list.
- Only N items are allowed in the list at once.
- Once N items are reached, items are removed from the bottom of the list.
- Can be databound to a DataGrid and not have to write any special UI code to do the above.
So in TDD fashion, I've written the following tests:
Which the following class passes:
When bound to a DataGridView, the behavior is as you would expect - items get added to the top, and "fall out" automatically as more are added. One quirk this brings out in the DataGridView is that it automatically scrolls to the bottom when an item is added or removed. I'm still looking for a better workaround for this, but the following works with a little bit of flicker:
Some work remains to be done. Some thread-safety needs to be added, and default constructors and so on- plus I imagine a little work to make it play well in WPF. But hopefully this will be useful to you!