This is a migrated thread and some comments may be shown as answers.

Selection of cells disappears after sorting and filtering

2 Answers 246 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Walter
Top achievements
Rank 1
Walter asked on 06 Oct 2011, 10:10 AM
Hi,

I have a gridview and the gridview has as SelectionMode="Multiple" and SelectionUnit="Cell".
My problem is now that the selection of the cells disappears after sorting or filtering the grid.  But I want that the selected cells stay selected also after sorting the grid.
If I use SelectionUnit="FullRow", then the selection of the rows don't disappear.

Why does the gridview act like this? Do I have to set some properties or do You know an easy way to implement this functionality on my own?

Thanks
Walter

2 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 07 Oct 2011, 08:22 AM
Hi Walter,

You could save the selected cells in a separate collection and after the grid is sorted/filtered to restore it back to the SelectedCells collection of the grid.
 

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Walter
Top achievements
Rank 1
answered on 07 Oct 2011, 11:49 AM

I've found the solution. I store the selected cells like You said in a collection in the sorting event. But the problem was in the sorted event. There I did myGridView.Select(items) (items were a list of first GridViewCell and then GridViewCellInfo) but this method didn't work. 
  Now the solution is to store the GridViewCellInfos in a list and the to restore the selections like this.
 

private IList<GridViewCellInfo> selection = new ObservableCollection<GridViewCellInfo>();    
         
private void myGridView_Sorted(object sender, GridViewSortedEventArgs e)    
{    
  foreach (GridViewCellInfo gridViewCellInfo in selection)    
  {    
     myGridView.SelectedCells.Add(gridViewCellInfo);    
  }    
}    
         
private void myGridView_Sorting(object sender, GridViewSortingEventArgs e)    
{   
  selection.Clear();    
  foreach (var gridViewCellInfo in ouGridView.SelectedCells)   
  {    
    selection.Add(gridViewCellInfo); 
  }    
  myGridView.UnselectAll();

Kind Regards,
Walter






Tags
GridView
Asked by
Walter
Top achievements
Rank 1
Answers by
Maya
Telerik team
Walter
Top achievements
Rank 1
Share this question
or