I have such DataGrid
<DataGrid AutoGenerateColumns="True" HorizontalAlignment="Stretch" Name="dataGrid1" VerticalAlignment="Stretch" ItemsSource="{Binding DataList}" IsReadOnly="True"/>
In my ViewModel I have such field:
public ObservableCollection<ConsoleData> DataList { get; set; }
And such method which is called every second:
private void model_DataArrived(List<ConsoleData> dataList)
{
DataList.Clear();
dataList.ForEach(x => DataList.Add(x));
}
Grid displays some real-time data and updates every second.
The problem is – when I select some row in the grid, the selection is reset after a second (when new data is arrived).
I guess probably this is because I Clear DataList every time?
How to solve this problem?
Before clear, pick up the currently selected item (a unique identifier if you have one) then attempt to highlight it again on update and if it’s not there anymore just don’t highlight annything.