Articles in this section
Category / Section

How to clear the selection while grouping or ungrouping in WPF DataGrid (SfDataGrid)?

1 min read

The first caption summary row is selected by default when you are grouping the column in WPF DataGrid (SfDataGrid). You can clear the default selection in first row while grouping or ungrouping by overriding GridSelectionController or GridCellSelectionController based on the SelectionUnit.

You can call SfDataGrid.ClearSelections (bool exceptCurrentRow) method inside ProcessOnGroupChanged override of selection controller to clear the selection while grouping and ungrouping.

C#

sfdatagrid.SelectionController = new GridSelectionControllerExt(this.sfdatagrid);
 
public class GridSelectionControllerExt : GridSelectionController
{        
    public GridSelectionControllerExt(SfDataGrid grid)
        : base(grid)
    {
           
    }
 
    protected override void ProcessOnGroupChanged(GridGroupingEventArgs args)
    {
        if (this.DataGrid.SelectionMode == GridSelectionMode.None)
            return;
        this.DataGrid.ClearSelections(false);
    }
}

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  to leave a comment
Access denied
Access denied