title: Retain selected row(s) in a datagrid after sorting
body: <p>I'm using a WPF datagrid in which multiple records can be selected &amp; it can be sorted (by clicking the column headers).</p>
  
  <p>I want to be able to <b><i>retain the selected rows</b></i> after the sort.</p>
  
  <p>Please note I can retain the selected row, the problem arises when the  rows to retain are more than 1.</p>
  
  <p><i>Say for example:</i> I select rows with indices 2 &amp; 3, and then sort on a particular column. After the sort functionality I want to be able to retain the selected rows (old indices-2,3) &amp; new indices - 4,5. Thus, after sorting, the 4th &amp; 5th rows must be selected.</p>
  
  <p>The items source for my datagrid is of type ListCollectionView to which I'm adding sort descriptions when reqd to sort.</p>
  
  <p><b>Things I have tried:</b></p>
  
  <p>Tried setting the SelectedItems property. Doesn't work since it is a Read Only property.</p>
  
  <p>Tried setting the IsSelected property of the DataGridRow(s), doesn't work. Though I can see the IsSelected property for the selected rows is set to true, on the screen I do not see the records highlighted.</p>
  
  <p>This one may be vague but I set the selected Index multiple times but this only highlights the record for the last selected index.</p>
  
  <p>Each time after sorting, the last selected record is highlighted. Is there a way by which I can retain the selected rows?</p>
  
  <p><b> EDIT: </B></p>
  
  <p>I'm now able to set the selected items of the datagrid using Datagrid.SelectedItems.Add(dataGridRow) or setting the IsSelected property on the datagrid row.</p>
  
  <p>The issue is though the selected items are present, they are not highlighted on the screen. How can I get the rows to be highlighted?</p>
  
  <p>For ex: If 3 records were selected &amp; highlighted before sort, after sort, all records are selected (put breakpoints &amp; checked in Code) but only one record is highlighted.</p>