Xceed Grid for WinForms v4.3 Documentation
How to delete a row when the Delete key is pressed

Welcome to Xceed Grid for WinForms v4.3 > Task-Based Help > Mouse and keyboard > How to delete a row when the Delete key is pressed

Any row can be deleted from the grid using the row's Remove method, however rows will not be automatically deleted when the delete key is pressed. 

In order to delete rows from the grid when the delete key is pressed, you need to handle the KeyDown event of the DataRowTemplate (for each DataRow in the grid) and the KeyDown event of any other row that you want to allow your end-users to delete. In the event handler, you can then check if the key that was pressed is the delete key and then remove the row from the grid. 

Demonstration

In the following example, we check to see if it was the delete key that was pressed. If it was, we check to make sure that the row is a DataRow and then we delete the row. The validation to check if the row is a DataRow is not necessary; Any type of row can be deleted using the Remove method.

VB.NET Copy Code

If e.KeyData = Keys.Delete Then
  If TypeOf sender Is Xceed.Grid.DataRow Then
    CType(sender, Xceed.Grid.DataRow).Remove()
  End If
End If

C# Copy Code

if( e.KeyData == Keys.Delete )
{
  if( sender is Xceed.Grid.DataRow )
  {
    ( ( Xceed.Grid.DataRow )sender ).Remove();
  }
}