Articles in this section
Category / Section

How to programatically invert selection in WPF GridControl?

1 min read

You can programmatically invert selection in GridControl by clearing existing selection and adding the cells other than previously selected cells GridControl.Model.SelectedRanges collection.

Refer below code for your reference.

C#

private void Button_Click(object sender, RoutedEventArgs e)
{
  var currentSelectedRanges = grid.Model.SelectedRanges.Clone();
  grid.Model.Selections.Clear(false);
  for(int i=1;i<=grid.Model.RowCount;i++)
  {
     for(int j=1;j<=grid.Model.ColumnCount;j++)
     {
        var cellRange = GridRangeInfo.Cell(i, j);
        if (!currentSelectedRanges.AnyRangeContains(cellRange))
        {
           grid.Model.SelectedRanges.Add(cellRange);
        }
     }
  }
  grid.Model.InvalidateVisual();
}

Invert selection in WPF GridControl

Sample: View sample in GitHub

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied