Category / Section
How to maintain the Selection, when the mouse is clicked inside the selected range in WPF GridControl?
1 min read
By default, when you click inside the selected range in Grid, the Selection is cleared. To maintain the Selection without clearing, when the mouse is clicked inside the selected range of Grid, you can use the PreviewMouseDown event of Grid control as illustrated in the following code example.
C#
grid.PreviewMouseDown += grid_PreviewMouseDown; void grid_PreviewMouseDown(object sender, MouseButtonEventArgs e) { var pt = grid.PointToCellRowColumnIndex(e); var range = GridRangeInfo.Cell(pt.RowIndex,pt.ColumnIndex); if (grid.Model.SelectedRanges.AnyRangeContains(range)) { e.Handled = true; } }