I
I
Ilya2014-10-09 09:33:47
WPF
Ilya, 2014-10-09 09:33:47

How to remember selected record in DataGrid?

Hello. Such is the question. I work with WPF and MVVM. How can I, after updating the collection, select the entry that was selected in the DataGrid (that is, SelectedIndex)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
olegivo, 2014-10-14
@olegivo

Solution, if the object that was selected remains in the collection:
1. add the SelectedItem property to the ViewModel (with INPC);
2. before updating the collection, remember it, after updating the collection - set the stored value into it;
3. in the DataGrid, add the binding of the selected grid element to the ViewModel property
SelectedItem="{Binding SelectedItem Mode=TwoWay}"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question