We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to delete the cell value by using the delete key in display mode?

Platform: WPF |
Control: SfDataGrid |
.NET Framework: 4.5

In the SfDataGrid, you can delete the selected row by pressing the Delete key when the SfDataGrid.AllowDeleting is set to true. Likewise, you can delete the selected cell value without entering into the edit mode when the delete key is pressed by deriving a new class from the GridSelectionController. In the customized GridSelectionController, you need to override the ProcessKeyDown virtual method that handles all the key navigations. With the help of the PropertyDescriptorExtensions.SetValue helper method, you can set the cell value as null. Before setting the value, you need to check whether the selected cell value is null as follows.


public class GridSelectionControllerExt : GridSelectionController
    public GridSelectionControllerExt(SfDataGrid grid)
        : base(grid)
    protected override void ProcessKeyDown(KeyEventArgs args)
        //Customizes the Delete key operation.
        if (args.Key == Key.Delete)
            //Gets the cell value of current column.
            var record = this.DataGrid.View.Records[this.DataGrid.SelectedIndex].Data;                               
            var cellVal = this.DataGrid.View.GetPropertyAccessProvider().GetValue(record, this.DataGrid.Columns[this.CurrentCellManager.CurrentCell.ColumnIndex].MappingName);
            //Returns the cell value when the current column's cell is not set to null.
            if (cellVal != null)
                var columnName = this.DataGrid.Columns[this.CurrentCellManager.CurrentCell.ColumnIndex].MappingName;               PropertyDescriptorExtensions.SetValue(this.DataGrid.View.GetItemProperties(), record, null, columnName);


Refer to the following code example to assign the customized GridSelectionControllerExt to the SfDataGrid.SelectionController to override the existing SelectionController.


public MainWindow()
    // Assigns the customized GridSelectionControllerExt.
    this.grid.SelectionController = new GridSelectionControllerExt(grid);


Sample Links:





2X faster development

The ultimate WPF UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile