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.
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 |
---|---|
|
C# | Copy Code |
---|---|
|