Hi,
In our application we have a xamDataGrid bound to an EntityCollection. This collection is filled with data from the server and is retrieved entirely as updating row may result in several rows being changed.
However we would like that the row being updated (and the one that might cause other rows being updated) remains selected after the entire collection is updated.
I tried the following code but it doesn't seem to work:
private void AdressenDerdeView_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "Results") { var vm = ViewModel as AdressenDerdeViewModel; if (dgContent.Records.Count > vm.IndexOfCurrentRow) { //dgContent.ActiveRecord = vm.Results.ElementAt(vm.IndexOfCurrentRow); var rec = dgContent.Records[vm.IndexOfCurrentRow]; dgContent.ActiveRecord = rec; // don't know if you really need this dgContent.ActiveRecord.IsSelected = true; } //vm.CurrentRow = vm.Results.ElementAt(vm.IndexOfCurrentRow); } }
How can we do this?
Hello,
You can add a binding for the ActiveDataItem in the Grid and then maintain this value when changing the DataSource.
See attached sample.
Please let me know if you have any questions.
Sincerely,
Valerie
Developer Support Supervisor - XAML
Infragistics
www.infragistics.com/support
I'm afraid it doesn't work. I use the following code.
IndexOfCurrentRow = Results.IndexOf(CurrentRow); Results = null; var tempResults = await _derdeService.UpdateAdres(CurrentRow); Results = tempResults; CurrentRow = Results[IndexOfCurrentRow];
It should be noted that the current row also changes in the process of updating the datasource, therefore it's not possible to just make a backup of the object.
What happens is that the CurrentRow is set correctly and then it is set again by the datagrid (we use MVVM and both Results (datasource) and CurrentRow (ActiveDataItem) are set through two way databinding).
I think the following might be causing the problem: the datagrid is sorted on a certain column that is an enumeration. The grid always selects the first row that has the same value for this enumeration as the old CurrentRow.
Kind regards!