Hello
I have a program where I use MVVM pattern where a list
of orders is displayed in a SfDataGrid. This data comes from a web server and the data is
pulled on a timer and on change the ItemsSource of the SfDataGrid is updated to
the new.
My problem is that every time this is done
all selection is reset and the DataGrid scrolls to the top.
The scrolling was easily fixed by setting
CanMaintainScrollPosition="True"
And the item I can also find again by
binding SelectedItem the
SelectedItem="{Binding SelectedOrder, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
And then after and update I will find that
same item again.
However the problem is that when I reset
the SelectedOrder to
the, old SelectedOrder before
the pull, the selected cell end up in the first column.
I have tried binding
CurrentColumn="{Binding SelectedColumn, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
And that way I can get the selected column but
when I the reset SelectedColumn to the one it was in before the pull in the VeiwModel it is not updated.
I also tried to bind to CurrentCellInfo but cannot get this
to work at all.
Version. 17.2.0.34
var selectedItems = this.dataGrid.SelectedItem;
this.dataGrid.ItemsSource = viewModel.Orders;
this.dataGrid.SelectedItem = selectedItems; |
var selectedIndex = this.dataGrid.SelectedIndex;
this.dataGrid.ItemsSource = viewModelCollection.Orders;
this.dataGrid.SelectedIndex = selectedIndex; |
var selectedItems = this.dataGrid.SelectedItem;
var currentCell = this.dataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex;
this.dataGrid.ItemsSource = viewModelCollection.Orders;
this.dataGrid.SelectedItem = selectedItems;
this.dataGrid.MoveCurrentCell(currentCell); |