I have a .NET 4.0 WPF DataGrid with about 2,000 sorted items and one selected item. The DataGrid is updated every 500 ms from a separate thread causing the items to be added and/or removed. After each update the collection of items gets sorted.
The problem is that if the selected item is near the middle of the list, it often goes away from a visible area after several updates. I am looking for a way to update the DataGrid without a user noticing it, i.e. keep the selected item on the same position in the visible area.
So far I have 2 ideas how to work around this problem, but none of them makes me proud:
ScrollIntoView. The problem with that uproach is that the program will have to loop through all items every 500 ms, which is quite a lot of work for a processor.I used to solve this problem in WinForms by using TopIndex property, but there is no equivalent of it in WPF.
To sum up, any ideas about how it is possible to add/delete items in a sorted and frequently updated DataGrid without a user having to chase an item of interest will be much appreciated.
Maybe you could take a look to the ScrollViewer and its members like VerticalOffset, ScrollToVerticalOffset. Let me know if it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With