How to catch delete line (from keyboard) in datagridview?

Background I have a custom collection attached to datagridview

this.datagridview.DataSource = mycollection

I have a delete button in the user interface. The user can click the delete button to delete the selected DX directory.

Some of the connected ones cannot be deleted, so I enable and disable the delete button.

It works great if the user deletes a record by clicking the delete butoon button.

The problem is this:

When the user clicked the delete button from the keyboard

How to lock the keyboard button "Delete". When I press the delete button from the keyboard:

- removes the selected row from the datagrid view. - When the user clicks save .., he also saves it in Xml.

To fix this, I handled the _RowRemoved event of the datagrid view .. but still didn't help

Please, help

+3
source share
2 answers

Attach to the UserDeletingRow event and cancel the deletion (if necessary) by settinge.Cancelled = true

+11
source

since you have a button that processes when they can “delete”, you can simply set:

CanUserDeleteRows="false"

directly to the DataGrid in XAML.

"" ( ), .

, "" ( ), UserDeletingRow , .

0

Source: https://habr.com/ru/post/1721672/


All Articles