I want to enable the user to highlight a row on the WPF DataGrid and press delete key to delete the row.
The RemovedItems
items reflects the items removed from the selection, and not from the grid.
Handle the PreviewKeyDown
event, and use the SelectedItems
property to delete the selected rows there:
private void PreviewKeyDownHandler(object sender, KeyEventArgs e) {
var grid = (DataGrid)sender;
if ( Key.Delete == e.Key ) {
foreach (var row in grid.SelectedItems) {
... // perform linq stuff to delete here
}
}
}