Loose selection after ItemsSource update.
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); |
In our last update, We did not use ViewModel. Before resetting the ItemsSource, get the current cell value and then call the MoveToCell() method for maintaining the current cell value. We just use the DataGrid ItemsSource collection.
Can you please explain, what is the exact issue you are facing from our suggestion and provide code snippet or issue reproducing video about this?
It will be helpful for us to investigate further.
Regards,
Susmitha S
- 6 Replies
- 3 Participants
-
KM Kasper Mathiesen
- Sep 4, 2019 12:07 PM UTC
- Sep 9, 2019 01:18 PM UTC