Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete DataGridView Row by pressing DeleteKey?

I have a DataGridView on a form.

I want to delete rows from the grid by pressing the delete key, but delete key seems to be dead, until I enter into CellEditMode.

If I enter to CellEditMode then the delete key works, but obviously only for deleting cell contents, not for deleting rows.

The DataGridView has AllowUserToDeleteRow = true and the grid is unbound.

I have other grids where this function works correctly, but can't see the difference.

like image 608
Bonaca Avatar asked May 20 '12 13:05

Bonaca


2 Answers

One possible cause for the delete functionality not working is that you need to have a row selected.

This means either having the SelectionMode set to FullRowSelect or means that you have previously clicked on the row headers which are to the left of the columns.

like image 192
David Hall Avatar answered Nov 17 '22 00:11

David Hall


If you are using DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter you can't delete any row

like image 1
Julio Avatar answered Nov 16 '22 23:11

Julio